When setting a cookie with client-side javascript document.cookie=...
, the secure
attribute forces the cookie "to only be transmitted over secure protocol as https" see MDN spec.
I set a cookie in my SPA, client-side (ie in code run by the browser) as follows:
document.cookie = 'myCookie=myValue;expires=Sun, 31 Dec 2017 23:00:00 GMT;path=/;secure;';
where Sun, 31 Dec 2017 23:00:00 GMT
is obtained with the javascript Date
method toUTCString()
, and could be any date in the distant future (there have been report with expires
issues when the date is less than 2 hours in the future, but this is not at stake here).
This works for Chrome on macOS and on android, but the cookie is not set on neither for Chrome nor Safari on iOS. After poking around, I figured that removing the secure
attribute allows the cookie to be set:
document.cookie = 'myCookie=myValue;expires=Sun, 31 Dec 2017 23:00:00 GMT;path=/;';
Does anyone know how I can set my cookie for Chrome and Safari on iOS for it to be transmitted only over https?
There surely must be a way, and I researched many SO questions to no avail. Thx