docs: recommend pairing with http.CrossOriginProtection for browser apps#274
Open
paskal wants to merge 1 commit intogo-pkgz:masterfrom
Open
docs: recommend pairing with http.CrossOriginProtection for browser apps#274paskal wants to merge 1 commit intogo-pkgz:masterfrom
paskal wants to merge 1 commit intogo-pkgz:masterfrom
Conversation
Coverage Report for CI Build 24543150534Coverage remained the same at 84.247%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
1cdb452 to
02a673e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a short README subsection under
## XSRF Protectionsrecommending that browser-based applications wrap their router with Go 1.25'shttp.CrossOriginProtectionin 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-TOKENcookie +X-XSRF-TOKENheader pair set bytoken.JWT) is solid but has two gaps for browser-based callers:X-JWTheader skip the check entirelySec-Fetch-Siteis 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. UnlikeSameSite=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 withhttp.CrossOriginProtection(Go 1.25+)" subsection with usage example and rationaleReferences