fix(server): add app-wide browser security headers (#1541) - #2026
Draft
bestony wants to merge 1 commit into
Draft
Conversation
|
All contributors are covered by the First Tree CLA. |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
14 tasks
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.
Summary
packages/server/src/security-headers.ts), wired as a root-levelonSendhook inbuildAppso every response — SPA shell, static assets, API JSON, error and 404 responses — carries the set.Content-Security-Policy(incl.frame-ancestors 'none'),Strict-Transport-Security,X-Content-Type-Options: nosniff,Referrer-Policy: strict-origin-when-cross-origin,X-Frame-Options: DENY,Permissions-Policy.Closes #1541
CSP notes
script-src 'self' 'unsafe-inline' https://www.googletagmanager.com https://www.clarity.ms—packages/web/index.htmlships three inline bootstrap scripts (GA4 loader, Clarity loader, theme init) which inject the GA4/Clarity tags from those hosts. Nonce-based hardening means rewritingindex.htmlper response and is left as follow-up work.connect-srcallows same-origin REST + WebSocket (ws:/wss:), GA4 collect, Clarity collect, and optional Sentry ingest (VITE_SENTRY_DSN).img-src 'self' data: blob: https:keeps user-pasted external images in chat markdown rendering.Validation
pnpm check(biome — changed files clean)pnpm --filter @first-tree/server typecheckpnpm --filter @first-tree/server test— newsecurity-headers.test.tscovers the policy shape (framing denied,object-src 'none', analytics/Sentry allowlist), header presence on SPA shell / API 404 //healthzviabuildApp+inject, and route-override preservation; full server suite greenChange Surface
apps/clipublic CLI or help outputNotes
@fastify/helmetto keep the policy explicit and the diff dependency-freepackages/server/src/__tests__/security-headers.test.tspackages/web/index.html; post-deploy verification per the issue —curl -sI https://<prod-host>/ | grep -iE 'content-security-policy|strict-transport-security|x-content-type-options|referrer-policy|x-frame-options'