Session cookies are what keep a user logged in. If they are set carelessly, an XSS bug, a shared network or a cross-site request can turn into an account takeover. AI-generated auth code often sets cookies with defaults, and defaults are rarely safe.
The four flags to check
- HttpOnly: JavaScript cannot read the cookie. Without it, any XSS bug can steal the session. Session and auth cookies should have it.
- Secure: the cookie is only sent over HTTPS. Without it, it can leak over plain HTTP.
-
SameSite:
LaxorStrictstops the browser sending the cookie on most cross-site requests, which blunts CSRF.NoneneedsSecureand should be a deliberate choice. -
Path and Domain: a cookie scoped to
.yourapp.comis sent to every subdomain, including a forgotten staging one.
How to check your own app
- Open your live site, log in, open DevTools, then Application, then Cookies.
- Look at each cookie that holds a session or token. Are HttpOnly and Secure ticked? What does SameSite say?
- Or run
curl -I https://yourapp.com/loginand read theSet-Cookielines.
Common mistakes in generated code
- Storing a JWT in
localStorageor in a cookie set from client-side JS, so HttpOnly is impossible. - Setting
secure: falsein dev config and shipping it. -
sameSite: 'none'copied from a CORS fix without understanding it. - Very long expiry on session cookies.
Fix
Set the cookie on the server with HttpOnly; Secure; SameSite=Lax; Path=/ and a sensible max age. In Express that is res.cookie('sid', value, { httpOnly: true, secure: true, sameSite: 'lax' }). In Next.js use cookies().set(..., { httpOnly: true, secure: true, sameSite: 'lax' }).
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.
Top comments (0)