feat(web): add security headers to corporate platform Next.js config - #610
Merged
Oluwaseyi89 merged 1 commit intoSep 2, 2026
Conversation
Apply a baseline security header set to every route via headers() in next.config.ts: Content-Security-Policy (frame-ancestors 'none', connect-src derived from NEXT_PUBLIC_API_BASE_URL), X-Frame-Options DENY, X-Content-Type-Options nosniff, Referrer-Policy strict-origin-when-cross-origin, Permissions-Policy, and production-only Strict-Transport-Security. The dev CSP keeps 'unsafe-eval' and WebSocket for hot reload while production drops both. Adds vitest coverage for the header configuration and documents the header set in SECURITY_HEADERS.md for future maintainers.
|
@odarome132 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #547
Summary
Implements the security-header hardening requested in #547 for the corporate platform web app.
next.config.tsnow applies a baseline security header set to every route via aheaders()rule withsource: '/(.*)'— previously the app had onlyCache-Controlcaching rules and zero browser-side hardening.What changed
corporate-platform/corporate-platform-web/next.config.ts— newbuildSecurityHeaders()helper, applied to all routes before the existing cache rules (no header-key overlap).corporate-platform/corporate-platform-web/src/next-config.test.ts— 11 vitest cases following the repo's pattern (colocatedsrc/**/*.test.ts, vitest globals).corporate-platform/corporate-platform-web/SECURITY_HEADERS.md— single source of truth for the header set, dev/prod differences, CSP design, and coordination with a futurevercel.json.Key design decisions
'unsafe-eval'andws:/wss:so Next.js hot reload keeps working; production drops both.Strict-Transport-Securityis production-only (max-age=63072000; includeSubDomains; preload) so plainhttp://localhostis never locked out in dev.connect-srcis built fromNEXT_PUBLIC_API_BASE_URL(defaulthttp://localhost:4000), so API calls are not blocked once the policy is enforced.img-srcmirrorsimages.remotePatterns(unsplash, pinata, jsdelivr, stellar) — a test asserts they stay in sync, so there's no regression forimages.unsplash.com.script-src 'self' 'unsafe-inline'is the documented minimum: Next.js injects inline bootstrap scripts and no nonce/hash strategy exists yet. Tightening is flagged as follow-up.frame-ancestors 'none'+X-Frame-Options: DENYblock clickjacking of authenticated corporate users.Acceptance-criteria checklist
next.config.tsexports anasync headers()applied to all routes —source: '/(.*)'Content-Security-Policy,X-Frame-Options,X-Content-Type-Options,Referrer-Policy,Permissions-Policy— test-verifiedStrict-Transport-Securitypresent in production —max-age=63072000; includeSubDomains; preload, test-verifiedconnect-srcallows the configured API base URL — test-verified (default + customNEXT_PUBLIC_API_BASE_URL)'unsafe-eval'+ws:/wss:, test-verifiedsrc/next-config.test.ts(11 tests)script-src/style-srckeep'unsafe-inline'(documented minimum)SECURITY_HEADERS.mdX-Frame-Options: DENYprevents iframe embedding — header asserted by test; browser-enforcedimages.remotePatternsbehavior — config untouched;img-srckept in sync, test-verifiedTest output + coverage
Coverage for the changed file (
npx vitest run src/next-config.test.ts --coverage --coverage.provider=v8 --coverage.include=next.config.ts):The uncovered lines are the pre-existing
redirects()/rewrites()functions, outside this change's scope — every line of the new security-header code is covered. No coverage threshold is configured in the repo;@vitest/coverage-v8was installed locally for the report only and is not committed (no lockfile churn).Honest follow-ups
script-src 'unsafe-inline'with a nonce/hash strategy (Next.js middleware or custom server) for a strict CSP.Content-Security-Policy-Report-Onlyrollout with a reporting endpoint before tightening further.headers()at all" claim is outdated (caching headers existed); the security headers were indeed missing.Security note
These headers block clickjacking (
X-Frame-Options: DENY+frame-ancestors 'none'), MIME-sniffing (nosniff), referrer leakage (strict-origin-when-cross-origin), unused permission abuse (Permissions-Policy), and protocol downgrade (HSTS, production). The CSP is intentionally permissive onscript-srcuntil a nonce strategy lands; nothing in the current app is blocked by it.