1

I am trying to create a cookie in Drupal 8.9 with SameSite=none with secure attribute, using the Symfony\Component\HttpFoundation\Cookie class but I am unable to do so as the class doesn't allow the secure attribute along with none.

Also, I tried setting the Cookie's secure parameter to TRUE but it results in infinite redirects in my site. I don't want to implement the solution on site level as it will affect other cookies capabilities. I just want to do this for one particular cookie I am creating.

$cookie = new Cookie(self::SIGMACOOKIENAME, TRUE, 0, '/', NULL, TRUE, FALSE, TRUE, self::SAMESITE_NONE); 

1 Answer 1

1

If you're setting SameSite=None, you'll need to set the Secure attribute for HTTPS.

If SameSite=None is set, the cookie Secure attribute must also be set (or the cookie will be blocked). https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite#none

2
  • Yes, if I set the Secure attribute then my site results in infinite redirects. Commented Dec 24, 2021 at 4:58
  • That’s the issue then, you’ll need to fix your site to work with HTTPS. For example, with letsencrypt. Commented Dec 24, 2021 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.