Skip to content

docs: modernize CSRF guidance for SameSite era - #124

Merged
acoshift merged 2 commits into
masterfrom
docs/csrf-guidance
Jul 19, 2026
Merged

docs: modernize CSRF guidance for SameSite era#124
acoshift merged 2 commits into
masterfrom
docs/csrf-guidance

Conversation

@acoshift

Copy link
Copy Markdown
Member

Follow-up to #123. The README's htmx CSRF note prescribed token middleware as the default. Modern guidance:

  • An explicitly set SameSite=Lax/Strict session cookie + never mutating on GET stops classic cross-site form CSRF in all modern browsers (explicit matters: default-Lax carries the Chrome Lax+POST grace window and isn't uniform across Safari/Firefox).
  • Remaining gap is same-site-but-cross-origin (subdomain takeover, user content on subdomains) — covered by rejecting mutating requests with a cross-origin Sec-Fetch-Site, a few lines of BYO middleware, which fits hime's philosophy better than token machinery.
  • Token middleware is demoted to "if you use it anyway", keeping the hx-headers wiring and the localStorage-snapshot caveat.

acoshift added 2 commits July 19, 2026 20:32
Explicit SameSite=Lax/Strict on the session cookie plus no-mutations-
on-GET stops classic cross-site form CSRF in modern browsers; recommend
a Sec-Fetch-Site check as defense-in-depth (subdomains are same-site)
and demote token middleware to an if-you-use-it-anyway note.
Go 1.25 stdlib ships the Sec-Fetch-Site guard (with Origin fallback,
trusted origins, and bypass patterns) — recommend wrapping the handler
instead of hand-rolling middleware.
@acoshift
acoshift merged commit efadca2 into master Jul 19, 2026
2 checks passed
@acoshift
acoshift deleted the docs/csrf-guidance branch July 19, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant