Fix admin CSRF rejection caused by no-referrer origin serialization - #15
Merged
Merged
Conversation
Under referrer-policy: no-referrer, browsers serialize the Origin header as "null" even on same-origin form POSTs (Fetch spec), so every admin write failed the same-host Origin check with 403 in a real browser while passing in tests and curl, which supply their own Origin. same-origin keeps the referrer inside the admin host and makes the browser send the real Origin, restoring the check's intent. A test pins the policy so it cannot regress. Co-Authored-By: Claude Fable 5 <[email protected]>
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.
Problem
Every admin write returned 403 "The request could not be verified" in a real browser.
The admin pages ship
referrer-policy: no-referrer. Per the Fetch spec (whatwg/fetch#1066), browsers serialize theOriginheader asnullunder that policy even for same-origin form POSTs. The CSRF middleware requires an HTTPS same-host Origin, so every browser submission failed — while the test suite and curl, which supply their own Origin header, passed.Reproduced live: an authenticated
POST /admin/spaceswithOrigin: https://shutter-control.traydr.devsucceeds; the same request withOrigin: nullreturns 403.Fix
Serve the admin pages with
referrer-policy: same-origin: the referrer still never leaves the host, and same-origin POSTs carry the real Origin. A test pins the header so the policy cannot regress to a value that breaks the Origin check.🤖 Generated with Claude Code