Skip to content

docs: recommend pairing with http.CrossOriginProtection for browser apps#274

Open
paskal wants to merge 1 commit intogo-pkgz:masterfrom
paskal:feat/csrf-middleware
Open

docs: recommend pairing with http.CrossOriginProtection for browser apps#274
paskal wants to merge 1 commit intogo-pkgz:masterfrom
paskal:feat/csrf-middleware

Conversation

@paskal
Copy link
Copy Markdown
Collaborator

@paskal paskal commented Apr 17, 2026

Adds a short README subsection under ## XSRF Protections recommending that browser-based applications wrap their router with Go 1.25's http.CrossOriginProtection in addition to the JWT XSRF check this library already ships.

Documentation only -- no API changes, no new packages, no new dependencies.

Why

The existing JWT XSRF check (the XSRF-TOKEN cookie + X-XSRF-TOKEN header pair set by token.JWT) is solid but has two gaps for browser-based callers:

  1. it only fires when the JWT arrives in a cookie -- requests authenticated via the X-JWT header skip the check entirely
  2. it operates inside the auth middleware, so cross-origin requests still reach handler code (and any earlier middleware) before being rejected

Sec-Fetch-Site is a forbidden header (the browser sets it; JS cannot forge it), shipped in all major browsers since 2023, and OWASP elevated it from defence-in-depth to a primary CSRF defence in its cheatsheet in December 2025. Unlike SameSite=Lax, it distinguishes same-origin from same-site, so subdomain attacks are blocked.

The two mechanisms compose naturally: the new middleware covers browser flows at the HTTP layer; the JWT XSRF still covers API clients sending the JWT-derived header.

What changed

  • README.md -- new "Browser apps: pair with http.CrossOriginProtection (Go 1.25+)" subsection with usage example and rationale

References

@paskal paskal requested a review from umputun as a code owner April 17, 2026 01:27
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 17, 2026

Coverage Report for CI Build 24543150534

Coverage remained the same at 84.247%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3212
Covered Lines: 2706
Line Coverage: 84.25%
Coverage Strength: 7.26 hits per line

💛 - Coveralls

@paskal paskal marked this pull request as draft April 17, 2026 01:33
The JWT XSRF check only fires when the JWT arrives in a cookie and
only after a request reaches the auth middleware. For browser-based
apps the recommended additional defence is Go 1.25's stdlib
http.CrossOriginProtection, which checks Sec-Fetch-Site at the HTTP
layer and so catches cross-origin requests regardless of how (or
whether) auth is carried.

Documentation only -- no API changes.
@paskal paskal force-pushed the feat/csrf-middleware branch from 1cdb452 to 02a673e Compare April 17, 2026 01:34
@paskal paskal changed the title v2: add CrossOriginProtection middleware for browser apps docs: recommend pairing with http.CrossOriginProtection for browser apps Apr 17, 2026
@paskal paskal marked this pull request as ready for review April 17, 2026 01:58
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.

2 participants