Dev.to Security 🔐 Cybersecurity 👁 0 📖 3 min read

Login works locally but the session cookie is missing in production (proofforge.live): 6 causes and the fixes that weaken your app

You log in, and it works on localhost. In production the login succeeds, then the next page acts like you are signed out. The auth cookie never shows up in DevTools, or it shows up and is not sent back. I'm part of the P

You log in, and it works on localhost. In production the login succeeds, then the next page acts like you are signed out. The auth cookie never shows up in DevTools, or it shows up and is not sent back. I'm part of the ProofForge team. This is the checklist I'd run, and the "fixes" that make it work by making your app less safe.

First, look at the actual cookie

Open DevTools, then Application, then Cookies. Find the login response in the Network tab and read its Set-Cookie header. Three things tell you most of the story: the Secure, SameSite and Domain attributes. A cookie the browser rejects is listed with a warning icon in the Network tab.

6 causes, most common first

  1. Secure cookie on a non-HTTPS URL. A Secure cookie is dropped over plain HTTP. Preview URLs, a staging domain without TLS, or an internal proxy hop can cause this. Test on the real HTTPS domain.
  2. SameSite=None without Secure. Browsers reject that pair. If your frontend and API are on different sites, you need both, and HTTPS on both.
  3. Frontend and API on different registrable domains. app.example.com and api.example.com can share a cookie with Domain=.example.com. example.com and example.vercel.app cannot. The cleanest fix is to serve the API under your own domain or proxy it through the same origin.
  4. The request does not send credentials. For cross-origin calls, fetch needs credentials: "include", and the server needs a specific Access-Control-Allow-Origin (not *) plus Access-Control-Allow-Credentials: true.
  5. A redirect or middleware drops the Set-Cookie. If you set the cookie on one response and then return a different one (for example a fresh redirect), the cookie is lost. In Next.js, set it on the same response object you return.
  6. A proxy or CDN strips or caches it. Check that responses with Set-Cookie are not cached, and that your proxy forwards the header.

The fixes to skip

  • Do not remove HttpOnly so your JavaScript can read the session. That lets any script injected into your page steal it.
  • Do not move the token to localStorage to get around cookie problems. It has the same exposure, with no HttpOnly protection.
  • Do not set SameSite=None everywhere "to be safe". Use Lax unless you truly need cross-site.
  • Do not allow every origin with credentials. Reflecting any Origin back with credentials lets any site act as your signed-in user.

A good production cookie

For a first-party session cookie: HttpOnly; Secure; SameSite=Lax; Path=/, with a sensible expiry. Add Domain only if you need subdomains to share it.

Check it from the outside

After you deploy, look at the headers a stranger gets. Check that the session cookie has HttpOnly, Secure and a SameSite value, and that your API does not answer Access-Control-Allow-Origin: * together with credentials.

Quick check

Run the free ProofForge scan on your live URL. It reads your public site, passively and read-only, for exposed keys, open data and missing security headers, and says pass, fail or inconclusive. It cannot see behind a login, so a clean result is not a full audit.

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.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.