Wrap router with http.CrossOriginProtection for CSRF defence#40
Open
paskal wants to merge 1 commit intoumputun:masterfrom
Open
Wrap router with http.CrossOriginProtection for CSRF defence#40paskal wants to merge 1 commit intoumputun:masterfrom
paskal wants to merge 1 commit intoumputun:masterfrom
Conversation
bumps go to 1.25 to pick up http.newcrossoriginprotection. the middleware checks sec-fetch-site (forbidden header set by all major browsers since 2023) with an origin/host fallback and rejects cross-origin state-changing requests at the http layer. ci and release workflows updated to go 1.25 to match go.mod.
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 Go 1.25's
http.NewCrossOriginProtection().Handlerto the global middleware chain inserver/server.go. Bumps go.mod from 1.24.1 to 1.25.0 (and CI/release workflows accordingly) since the middleware is new in 1.25.Why
The admin htmx UI issues many state-changing requests (POST /api/v1/feeds, PUT /api/v1/feeds/{id}, POST /api/v1/feeds/{id}/enable, DELETE /api/v1/feeds/{id}, POST /api/v1/topics, PUT /api/v1/preferences, etc) that today have no CSRF defence. An attacker page running JavaScript in a victim's browser can issue cross-origin POSTs to these endpoints; if the user is logged in, the requests succeed.
http.CrossOriginProtectionchecks the browser-setSec-Fetch-Siteheader (a forbidden header JS cannot forge, shipped in all major browsers since 2023) with anOriginvsHostfallback for older clients. OWASP elevated this algorithm from defence-in-depth to a primary CSRF defence in its cheatsheet in December 2025.What changed
server/server.go-- one line insetupMiddleware()server/server_test.go-- newTestServer_CrossOriginProtectioncovering same-origin / cross-site / origin-host-mismatch / non-browser casesgo.mod-- go 1.24.1 → 1.25.0 (required forhttp.NewCrossOriginProtection).github/workflows/ci.yml,.github/workflows/release.yml-- Go version bumped to matchBehaviour notes
Sec-Fetch-Site: same-originis sent and the middleware passes them through. Verified end-to-end via the new test.Sec-Fetch-Site-- treated as non-browser, allowed.References