Skip to content

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:

  1. Lax still sends cookies on top-level GET navigations. Any endpoint that mutates on GET — GET /admin/delete?id=3 is the embarrassing classic — remains fully exposed. State changes belong on POST/PUT/DELETE anyway; SameSite makes that correctness into a security boundary.
  2. Same-site is not same-origin. The SameSite boundary is the eTLD+1 "site," not the host. staging.bank.example → bank.example is 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.
  3. Lax+POST. Chrome grants freshly-set cookies without an explicit SameSite attribute a two-minute window where they ride top-level cross-site POSTs, to keep old SSO flows working. Set SameSite explicitly 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: 1 or X-Requested-With on mutations. HTML forms can't set custom headers, and a cross-origin fetch with one triggers a CORS preflight your API can fail. Cheap, effective — SudoSecurity's own Collab app requires X-Collab on mutations for exactly this reason.
  • Origin / Sec-Fetch-Site verification: Sec-Fetch-Site: cross-site on a mutation is a strong reject signal; same-origin/same-site is what you expect.
  • Defense in depth: SameSite=Lax or Strict on 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.