Is your session cookie safe? HttpOnly, Secure and SameSite: a 2-minute check
Your app signs users in and remembers them with a cookie. If that cookie is set without the right flags, a script on the page can steal it, or another site can send it along with a forged request. Three small flags decid
Your app signs users in and remembers them with a cookie. If that cookie is set without the right flags, a script on the page can steal it, or another site can send it along with a forged request. Three small flags decide this: HttpOnly, Secure and SameSite.
AI-built apps often store the session token somewhere easier to reach, like localStorage, or set a cookie with none of the flags, because the login works either way in the demo.
What each flag does
- HttpOnly: page JavaScript cannot read the cookie. If an attacker finds an XSS hole, they cannot lift the session token.
- Secure: the cookie is only sent over HTTPS, never over a plain connection.
-
SameSite:
LaxorStrictstops the browser sending the cookie on most requests started by other sites. This is your main defense against CSRF.
The 2-minute check (your own app only)
- Sign in to your app with a test account.
- Open dev tools, then Application (Chrome) or Storage (Firefox), then Cookies.
- Find the session cookie. Look at the HttpOnly, Secure and SameSite columns.
- Also look in Local Storage and Session Storage. If you see a long token that starts with
eyJ, your session may live there, and any script on the page can read it. - In the Console, type
document.cookie. If your session cookie shows up, HttpOnly is off.
Pass: the session cookie has HttpOnly, Secure, and SameSite set to Lax or Strict, and no session token is in local storage.
What to fix
- Set the three flags wherever the cookie is created. Most auth libraries have a setting for each.
- Move the session token out of
localStorageand into an HttpOnly cookie. - Use
SameSite=Laxas a default, andStrictfor sensitive apps, then retest login flows that come from other sites. - Keep session lifetimes short and invalidate them on logout.
A prompt you can paste into your AI builder
"Review how the session is stored. Use a cookie with HttpOnly, Secure and SameSite=Lax, and do not keep auth tokens in localStorage or sessionStorage. Make logout invalidate the session on the server."
What a scanner can and cannot tell you
An outside check can see cookies that the server sets on public pages, so it can flag missing flags there. It does not sign in, so it cannot see the cookie your app sets after login. That one you check yourself, as above.
I work on ProofForge. The free scan covers the outside view and says plainly what it could not check.
Check your own app from the outside, free. Run the free ProofForge scan on your live URL. No account needed for the first scan. It looks at your public site the way a stranger would and says pass, fail or inconclusive, so you know what is confirmed and what it could not see. One-time reports start at $9: see pricing. Building with an AI agent? There is an MCP server so it can check before it deploys.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.