How to set both secure and samesite:strict in cookie creation?

Viewed 616

I am trying to get this line to work in JS:

document.cookie = cname+ "=" +cvalue+ ";" +expires+ " ;path=/; Secure; SameSite=strict";

When I try this, I get the following console output:

Cookie “cookieName” will be soon rejected because it has the “SameSite” attribute set to “None” or an invalid value, without the “secure” attribute.

I am not using secure with None, I am using secure with Strict for SameSite. What exactly is going on here, and can I use samesite:strict and secure:true without needing to change that strict to none?

1 Answers

Try:

SameSite=Strict; Secure;

This worked for me!

Check the order. Secure starts with an capital letter. After Strict an secure is a semicolon. Do you also submit a date for expires (expires = ?) See my comment below with an working example that I have in production.

An you can see also here: samesite-examples in JavaScript by GoogleChromeLabs

Related