Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Cookies are sometimes empty

$
0
0
Dear friends,
I'm using a nginx dockerized image with this server block:

server {
listen 80;
listen [::]:80;
server_name localhost;

location / {
add_header Set-Cookie "username=$http_matricola; Domain=localhost; SameSite=Lax; Path=/" always;
root /usr/share/nginx/html;
index index.html index.htm;
}
}

My nginx homepage was modified to do this:

<body>
<h1>Welcome to nginx!</h1>
<script>function listCookies() {var theCookies = document.cookie.split(';'); var aString = ''; for (var i = 1 ; i <= theCookies.length; i++) { aString += i + ' ' + theCookies[i-1] ; } return aString;} console.log(listCookies()); </script>
</body>

I am setting a custom request header via the modheader chrome extention. The odd thing that happens is that if I refresh the page, approximately 25% of the time the cookie is printed with an empty value.

In other words, 75% of the times that I press the page refresh button, it prints the cookie key and value correctly, while the other 25% it prints the cookie key, but with no value next to it. If I open the web console and go to Application and Cookie, the cookie is there and always has the value set, even when it's not printed via javascript.

Is there a race condition between nginx setting the cookie and the javascript printing it?

Thank you very much,
Roberto

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>