Lesson 4 of 14 · 14m
CSRF Still Works
SameSite=Lax default killed most ambient-authority CSRF — the same-site boundary, Lax+POST, and GET mutations are the gaps left over.
The ambient-authority bug
Browsers attach cookies to outgoing requests based on where the request goes, not where it was initiated. A page on evil.example can render <form action="https://bank.example/transfer" method="POST"> and auto-submit it; the browser ships the victim's session cookie along, and the server sees an authenticated request. That's the whole bug — ambient authority. The original poster child was the Samy worm in October 2005, which rode MySpace profile pages to force-add friends; the worm itself was XSS, but the propagation primitive was the same "your browser sends your credentials anywhere" property that makes CSRF work.
The wrong mental model
"SameSite=Lax is the default now, so CSRF is dead." Three gaps survive:
- Lax still sends cookies on top-level GET navigations. Any endpoint that mutates on GET —
GET /admin/delete?id=3is the embarrassing classic — remains fully exposed. State changes belong on POST/PUT/DELETE anyway; SameSite makes that correctness into a security boundary. - Same-site is not same-origin. The SameSite boundary is the eTLD+1 "site," not the host.
staging.bank.example→bank.exampleis a same-site request: SameSite doesn't filter it at all. Every sibling subdomain you control is inside the perimeter. Combine that with a subdomain takeover or a developer app on another port and the Lax default buys nothing. - Lax+POST. Chrome grants freshly-set cookies without an explicit
SameSiteattribute a two-minute window where they ride top-level cross-site POSTs, to keep old SSO flows working. SetSameSiteexplicitly and the exemption doesn't apply — but "explicitly" is the operative word.
And none of it helps non-cookie auth, non-browser clients, or CORS-relaxed APIs that accept simple requests.
SameSite=Strict trades the Lax+POST hole for a UX edge: inbound links from anywhere else — email, docs, a partner site — arrive without cookies, so users land logged-out on the first click. Lax is the default answer for user-facing apps; Strict is right for admin surfaces where you want external links to arrive unauthenticated.
The defenses that remain
- Synchronizer token: server mints a per-session (or per-request) random token, embedded in forms/headers; mutations reject without it. The canonical fix — the attacker can send the form but can't know the token.
- Double-submit cookie (the popular shortcut that isn't): send the token both as a cookie and as a request parameter, compare server-side. It fails because it assumes the attacker can't set cookies on your domain — subdomain cookie tossing and
Domain=sloppiness break exactly that assumption. If you double-submit, sign the cookie value or bind it to the session; a bare attacker-set cookie defeats the naive version. - Custom header check: require a non-simple header like
X-CSRF: 1orX-Requested-Withon mutations. HTML forms can't set custom headers, and a cross-originfetchwith one triggers a CORS preflight your API can fail. Cheap, effective — SudoSecurity's own Collab app requiresX-Collabon mutations for exactly this reason. Origin/Sec-Fetch-Siteverification:Sec-Fetch-Site: cross-siteon a mutation is a strong reject signal;same-origin/same-siteis what you expect.- Defense in depth:
SameSite=LaxorStricton the cookie itself as the outer layer.
None of this applies to Authorization-header auth — a token the browser doesn't attach automatically is CSRF-proof by construction, which is the real reason SPAs moved auth there; the storage trade that move forces is the next module's problem.
What to actually do
Mutations never on GET. Cookie carries explicit SameSite=Lax (or Strict where flows allow). Mutations require a synchronizer token or a custom header — pick one and enforce it centrally, in middleware, not per-route. Check Origin/Sec-Fetch-Site on anything sensitive. And remember the perimeter is the eTLD+1: audit sibling subdomains, because SameSite won't.
Keep reading
Related articles from the SudoSecurity blog.
A 257-Byte Password Is the Key: Inside the OpenSSH musl Bypass
CVE-2026-123158 lets an attacker log into a locked account on musl-based systems like Alpine by sending a password nobody set. The trigger is one number, 257, and the reason is a C library returning a single asterisk. I reproduced the exact boundary against musl 1.2.4 and read the fix.
Zero-Trust Access for Homelabbers: Teleport vs. Tailscale vs. WireGuard vs. Cloudflare Tunnel
Four tools solve four different problems that all get pitched as the same problem. Here's what each one does, where each one breaks, and the combination that covers a real homelab without paying an SSO tax you didn't see coming.
The SSO Tax: Why Self-Hosted Projects Are Gating Login Behind a Paywall
A growing list of open-core self-hosted projects, from Grafana to Planka, gate single sign-on behind an Enterprise tier. Here's which protocol actually gets paywalled, and what to check before you deploy.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.