Repository navigation
security: add proxy with nonce CSP and cookie gate; static headers (PR 1.2) - #10
Merged
Merged
Conversation
PR 1.2 of docs/MILESTONES.md (SECURITY §2.9, §2.1). - server/security/headers.ts: pure CSP builder (nonce + strict-dynamic for scripts, explicit per-vendor connect-src, no eval in production) and the static header set; unit-tested. CSP_MODE starts report-only (RISKS R9). - proxy.ts (Next 16 name for middleware): per-request nonce, CSP on request + response so Next attaches the nonce to its scripts, and a cookie-presence redirect for non-public paths (defence in depth; the verified gate stays getCurrentUser/requireUser). - next.config.ts: HSTS, nosniff, X-Frame-Options, Referrer-Policy, Permissions-Policy on every response. Server Actions keep Next's default same-origin check; allowedOrigins deliberately unset. - Report-only review in a real browser: inline-style violations came from React style attributes (style-src changed to 'self' 'unsafe-inline'; scripts stay nonce-only); one eval report is @firebase/util's guarded global probe, so eval stays blocked; upgrade-insecure-requests is emitted only when enforcing. - e2e asserts the headers on pages and API routes and that the nonce appears on Next's script tags. Verified: pnpm lint, typecheck, knip, vitest 24/24, next build, Playwright 15/15 on a production build; curl shows the served policy. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch had an error being deployed
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
PR 1.2 of
docs/MILESTONES.md(Phase 1). Implements SECURITY §2.9 (HTTP hardening) and the cookie-presence gate from §2.1, using Next 16'sproxy.ts(read from the bundled docs before writing).server/security/headers.ts— pure CSP builder (per-request nonce +'strict-dynamic'for scripts, explicit per-vendorconnect-src, no eval in production) and the static header set; unit-tested.CSP_MODE = "report-only"to start (R9).proxy.ts— nonce generation, CSP on request + response (so Next attaches the nonce to its own scripts), redirect to/sign-inwhen the session cookie is absent on non-public paths (defence in depth;requireUser/getCurrentUserremain the verified gate)next.config.ts— HSTS,nosniff,X-Frame-Options,Referrer-Policy,Permissions-Policyon every response incl. API routes. Server Actions keep Next's default same-origin check (allowedOriginsdeliberately unset — it only widens; docs corrected)Report-only review (R9 procedure)
Loaded
/sign-inand/sign-upin a real browser and read every CSP report:style={}attributes; a nonce instyle-srcmakes browsers ignore'unsafe-inline', so the policy isstyle-src 'self' 'unsafe-inline'with scripts nonce-only (rationale in code)unsafe-eval—@firebase/util'snew Function("return this")global probe, try/catch-guarded with a fallback → eval stays blockedupgrade-insecure-requestsis ignored in report-only mode → emitted only when enforcingFlip to enforce in its own PR after P1.6 (Sentry CSP reporting gives visibility on authenticated pages); re-review at P2.6 (R2 domain) and P5.3 (Gemini Live WebSocket).
Type
Verification
pnpm lint✔ ·typecheck✔ ·knip✔ ·vitest24/24 ·next build✔ (proxy registered)<script nonce>tagscurl -D -on/sign-inshows the exact served policyServer checklist
process.envoutsideconfig/env.ts(proxy readsenv.NODE_ENV)Risk watch-list
Docs
docs/SECURITY.md§2.9 rewritten to match the implemented policy;docs/RISKS.mdR9🤖 Generated with Claude Code