SameSite=Lax Silently Ate My Auth Cookies

February 12, 2026

Part of The Great 404 Debugging Saga. Can be read standalone.

The Setup

My app has a pretty standard cross-subdomain architecture: frontend on app.example.com, backend API on api.example.com. Login hits POST /api/v1/auth/login, which sets an auth_token cookie. Every subsequent request sends that cookie for authentication.

This worked perfectly in development where everything ran on localhost. It worked when I curled the API directly. It worked in Postman. It worked everywhere except the one place that mattered โ€” the actual production browser.

The Symptom

Login returned 200 OK. The Set-Cookie header was there. Chrome DevTools showed the cookie stored in the browser. Everything looked correct.

But the next API call โ€” fetching the user's dashboard data, listing cities, anything authenticated โ€” came back 401 Unauthorized. Or sometimes the request just failed with a CORS error, which sent me down a completely unrelated rabbit hole for hours.

The cookie was there. The browser had it. It just... wasn't sending it.

The Non-Clue

What made this maddening was the absence of any error message. There's no console warning that says "hey, I'm not sending your cookie because of SameSite policy." The cookie is in the jar. The request goes out. The cookie stays home. The server sees an unauthenticated request and returns 401. From the server's perspective, the client simply never sent credentials.

I checked CORS headers โ€” all correct. I checked withCredentials: true on the fetch client โ€” set. I checked the cookie domain โ€” .example.com, correct for subdomains. I checked Secure flag โ€” set, and we're on HTTPS. Everything looked right.

The Culprit

Buried in the auth handler:

c.SetSameSite(http.SameSiteLaxMode)
c.SetCookie("auth_token", token, maxAge, "/", domain, true, true)

SameSite=Lax.

Here's what Lax actually means in practice: the browser will send the cookie on top-level navigations (clicking a link, typing a URL) but will not send it on cross-origin AJAX/fetch requests. Since my frontend on app.example.com is making fetch calls to api.example.com, that's a cross-origin request. Lax says no.

The mental model most people have is: "Lax is the safe default, it works for most things." And it does โ€” if your frontend and backend are on the same origin. The moment they're on different subdomains and you're making programmatic requests, Lax silently drops your cookies.

The Fix

if isProduction {
    c.SetSameSite(http.SameSiteNoneMode)  // allows cross-origin
} else {
    c.SetSameSite(http.SameSiteLaxMode)   // fine for localhost
}
c.SetCookie("auth_token", token, maxAge, "/", domain, true, true)

SameSite=None requires Secure=true (HTTPS only), which was already set. That's it. One-line change.

Why This Was Hard to Find

Three reasons:

No error message. The browser doesn't tell you it's withholding a cookie. The request goes out, the cookie stays behind, the server returns 401. You're left debugging an authentication failure with no indication that the problem is in cookie transmission, not in your auth logic.

It worked locally. On localhost, everything is same-origin. Lax happily sends cookies. The bug only appeared in production where subdomains made it cross-origin. The classic "works on my machine."

I was already debugging something else. This bug surfaced in the middle of a larger debugging saga involving stale containers, Cloudflare caching, and PWA service workers. When authenticated requests started failing, my first instinct was "the old container is probably serving stale auth responses" โ€” not "the cookie isn't being sent at all." I wasted time investigating the wrong layer before isolating the cookie behavior.

Quick Reference

SameSite valueSame-origin requestsCross-origin top-level navigationCross-origin AJAX/fetch
StrictSentNot sentNot sent
LaxSentSentNot sent
None (+ Secure)SentSentSent

If your frontend and API are on different subdomains and you're using cookie-based auth with fetch or XMLHttpRequest, you need SameSite=None. There's no way around it.

ยฉ 2026 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2026-02-12). SameSite=Lax Silently Ate My Auth Cookies. https://caiborui.com/blog/2026-02-12-en-samesite-lax-ate-my-cookies

@misc{borui2026-1d32d54d,
  author = {borui},
  title = {{SameSite=Lax Silently Ate My Auth Cookies}},
  year = {2026},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2026-02-12-en-samesite-lax-ate-my-cookies}
}