Repository navigation
fix(security): send clickjacking, HSTS and nosniff headers on every response - #90
Open
lorenzocorallo wants to merge 1 commit into
Open
lorenzocorallo wants to merge 1 commit into
lorenzocorallo wants to merge 1 commit into
Conversation
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 58 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.
What was missing
The app sent none of the usual security headers.
curl -sI https://auth.polinetwork.org/shows noX-Frame-Options, no CSPframe-ancestors, noStrict-Transport-Security, noX-Content-Type-Optionsand noReferrer-Policy.What an attacker could do
The session cookie is
SameSite=Lax. A page on any other*.polinetwork.orgsubdomain counts as the same site, so it could load our pages in a hidden frame with the person still signed in. It could then trick them into clicking on:/consent, which can give an MCP agent the person's rights, admin rights included;/logout;What this PR sends now
Every response gets:
X-Frame-Options: DENYContent-Security-Policy: frame-ancestors 'none'; base-uri 'self'; object-src 'none'X-Content-Type-Options: nosniffReferrer-Policy: strict-origin-when-cross-originStrict-Transport-Security: max-age=31536000; includeSubDomains, only whenBETTER_AUTH_URLis https. Local development runs on http, so it does not get it. Nopreload.If a response already has one of these headers, it is left as it is.
Cache-Controland the CORS headers on.well-knowndo not change.The list lives in one small function,
src/lib/security-headers.ts. Two places use it:src/start.ts. It runs first, so it covers pages, server functions and server routes (/api/auth/*,/api/mcp,/.well-known/*). If a response's headers cannot be changed, it adds them to a copy of the response.src/nitro/security-headers.ts. Files frompublic/(/assets/*,/favicon.ico) and Nitro's own error pages never reach the middleware, so the plugin covers them.What the CSP leaves out, on purpose
form-action. The sign-out form posts and is then redirected to the application's own address.form-actionwould block that redirect.script-srcordefault-src. The page has an inline theme script and hydration scripts, which these would block.How it was tested
vp run buildand ran the production server against a local Postgres. Checked with curl that these all carry the headers:/,/consent,/logout(307),/users(401),/api/auth/get-session,/api/mcp(401),/.well-known/oauth-authorization-server(CORS andCache-Controlunchanged), a 404 page, a refused server function call (403),/favicon.ico, a built JS file and a missing asset.BETTER_AUTH_URL: HSTS shows up. With http it does not.vp dev.vp dev, Vite serves/favicon.icoitself, so it has no headers there. This only happens in development.vp checkpasses.vp testpasses: 372 tests ran with a local database, including the database integration tests. 117 were skipped because they need a running app and OAuth client settings.curl -sI https://auth.polinetwork.org/to confirm.