I have a Javascript script that opens a popup window passing a JWT token to a page.
This page uses the JWT token and creates a session, storing its ID in a cookie.
Once this is done, I am authenticated on the page.
It turns out that if I click again on the script that opens the popup, the JWT is passed again and the last cookie is "forgotten", it does not detect the previous session and redoes the entire authentication.
Is there any way for the previous cookie to remain? Is this caused by the cookie being HTTPOnly?
It is probably not related to HttpOnly, which only blocks access from JavaScript (hides it from the
document.cookieproperty).There is not enough information to solve it, but here are some ideas.
Are the original page and the popup on the same domain (origin)? If not, maybe it could be related to the SameSite attribute.
Are you sure the session cookie is not sent to the second popup? Can you check HTTP logs? (If you can't see it in Developer Tools because they open too late, either log it server side, or try using
chrome://net-export/.)Maybe the session cookie is sent, but the popup page doesn't check or read the cookie, it just unconditionally creates a new session.
Does it also happen when it's a normal page load instead of a popup?
To prove HttpOnly is not the problem, here is a tiny demo node.js server in which the popup can tell if you already have a cookie or not.