StoicBuilder

HandbookIII the CastraSessions and cookies

IIIthe Castra, Stay in control

Sessions and cookies

1 min readUpdated 28 November

In plain words

After you log in, your browser holds a small token, usually in a cookie, and sends it with every request to prove it's still you.

Where you see it

Open your browser's dev tools, go to Application, and look under Cookies or Local Storage: Supabase keeps an sb-...-auth-token there, Clerk a __session cookie. Delete it, refresh, and you're logged out.

Response headersserver
Set-Cookie: session=7f3a9c...; HttpOnly; Secure; SameSite=Lax; Path=/; Max-Age=604800
HttpOnly hides it from scripts, Secure keeps it on HTTPS, Max-Age ends it after a week.

What goes wrong

  1. Setting the session cookie from browser code

    A cookie written with document.cookie can't be HttpOnly, so any script on the page, including an injected one, can read it and copy the session.

    document.cookie = "session=" + token;
  2. Building your own login tokens

    Hand-made sessions often skip expiry, signing or the right cookie flags. Supabase Auth, Clerk, Auth.js and Better Auth handle all three.

  3. Logout that only clears the screen

    Some hand-written logout buttons reset the page but leave the token in place. The next person at that computer is still logged in as you.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Use our auth provider's built-in session handling instead of custom tokens. If sessions live in cookies, make them HttpOnly, Secure and SameSite=Lax with an expiry, and confirm that logging out ends the session on the server, not only on the page.

Quick check

Sign in to earn +10 XP for it

A Chirp user logs out on a library computer. The next person opens Chirp and is still logged in as them. Most likely cause?

Got a prompt that touches sessions and cookies?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.