Skip to content

Content Security Policy and HTTP Security Headers #554

Description

@Kingsman-99

Description

The Next.js app currently ships without a Content Security Policy or other hardening headers, making it vulnerable to XSS, clickjacking, and MIME-sniffing attacks. All security-relevant HTTP headers should be configured in one place and enforced for every response, including API routes and RSC payloads.

Technical Context

Headers configured in next.config.js under the headers() async function, supplemented by a middleware file at src/middleware.ts for dynamic CSP nonce injection. Headers to add: Content-Security-Policy, Strict-Transport-Security, X-Frame-Options: DENY, X-Content-Type-Options: nosniff, Referrer-Policy: strict-origin-when-cross-origin, Permissions-Policy. The CSP script-src directive must accommodate Next.js inline scripts via a per-request nonce passed through src/lib/csp.ts.

Acceptance Criteria

  • Running curl -I against any app route shows all six headers present with correct values
  • The CSP nonce is regenerated per request and injected into every inline <script> tag via the middleware
  • No browser console CSP violations appear during normal invoice creation or wallet connection flows
  • X-Frame-Options: DENY prevents the app from being embedded in an iframe on a third-party origin
  • A Lighthouse security audit or securityheaders.com scan returns an A grade
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions