{"success":true,"name":"configure-sessions-and-cookies-so-they-can-t-be-stolen-or-re","description":"Setting up sessions, auth cookies, or 'remember me' in a web app","category":"ai-brimind","path":"ai-brimind/configure-sessions-and-cookies-so-they-can-t-be-stolen-or-re/SKILL.md","file":"SKILL.md","content":"---\nname: configure-sessions-and-cookies-so-they-can-t-be-stolen-or-re\ndescription: \"Setting up sessions, auth cookies, or 'remember me' in a web app\"\n---\n\n# Configure Sessions and Cookies So They Can't Be Stolen or Reused\n\n## When to use\nYou are writing or configuring how the app keeps users logged in with cookies or sessions, including logout and 'remember me'.\n\n## Example request\nAuth cookie without HttpOnly → any script injection can read it and steal the session; HttpOnly keeps cookies away from JavaScript (cookie flags). Cookie sent over plain HTTP → anyone on the network can copy it; Secure forces HTTPS-only (transport protection). No SameSite setting → other sites can trigger logged-in actions from the user's browser; SameSite limits cross-site sending (CSRF defense). Logout only deletes the cookie in the browser → the session still works if someone saved it; the server must destroy the session too (server-side invalidation).\n\n## Instructions\nAct like a developer who treats the session cookie as the key to the user's whole account, because it is. When setting up sessions, use the framework's session mechanism rather than inventing one, then verify its configuration line by line: HttpOnly on (scripts cannot read the cookie), Secure on (HTTPS only), SameSite set (Lax or Strict, so other sites cannot ride the session), a sensible expiry, and a session ID that is long and random, generated by the framework. Handle the lifecycle on the server: regenerate the session ID after login (blocks session fixation), destroy the session server-side on logout and on password change, and give 'remember me' its own long-lived, revocable token instead of an eternal session. If the app changes state via requests that cookies authorize, confirm CSRF protection is active — most frameworks include it; check it is not disabled. Only ship once each flag and lifecycle step is explicitly set and you can explain which theft or reuse attack it blocks (XSS cookie theft, network sniffing, CSRF, fixation), not just that login appears to work.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #534\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}