Repository navigation
security: add CSP and security headers to console-ui (SEC-014) #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,48 @@ | ||
| import type { NextConfig } from "next"; | ||
|
|
||
| // Content-Security-Policy directives. | ||
| // - 'unsafe-inline' for style-src: required by Next.js for injected styles. | ||
| // - 'unsafe-inline' + 'unsafe-eval' for script-src: required by Privy SDK | ||
| // and Next.js dev mode. Tighten to nonce-based CSP when feasible. | ||
| // - connect-src: coordinator API, Privy auth, Google Analytics, Stripe. | ||
| // - frame-src: Privy auth iframes, Stripe Checkout iframes. | ||
| const cspDirectives = [ | ||
| "default-src 'self'", | ||
| "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.googletagmanager.com https://js.stripe.com", | ||
| "style-src 'self' 'unsafe-inline'", | ||
| "img-src 'self' data: blob: https:", | ||
| "font-src 'self' data:", | ||
| "connect-src 'self' https://api.darkbloom.dev https://*.privy.io wss://*.privy.io https://www.google-analytics.com https://api.stripe.com", | ||
| "frame-src https://auth.privy.io https://js.stripe.com", | ||
| "frame-ancestors 'none'", | ||
| "base-uri 'self'", | ||
| "form-action 'self'", | ||
| ].join("; "); | ||
|
|
||
| const securityHeaders = [ | ||
| { key: "Content-Security-Policy", value: cspDirectives }, | ||
| { key: "X-Frame-Options", value: "DENY" }, | ||
| { key: "X-Content-Type-Options", value: "nosniff" }, | ||
| { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" }, | ||
| { key: "Strict-Transport-Security", value: "max-age=63072000; includeSubDomains; preload" }, | ||
| { key: "Permissions-Policy", value: "camera=(), microphone=(), geolocation=()" }, | ||
| ]; | ||
|
|
||
| const nextConfig: NextConfig = { | ||
| typescript: { | ||
| // @noble/curves >=1.9 ships raw .ts files with .ts import extensions, | ||
| // which fails Next.js type-checking even with skipLibCheck: true. | ||
| // This is a known upstream issue in viem's dependency tree. | ||
| ignoreBuildErrors: true, | ||
| }, | ||
| async headers() { | ||
| return [ | ||
| { | ||
| source: "/(.*)", | ||
| headers: securityHeaders, | ||
| }, | ||
| ]; | ||
| }, | ||
| }; | ||
|
|
||
| export default nextConfig; | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new CSP hardcodes
connect-srctohttps://api.darkbloom.dev, but the UI intentionally supports alternate coordinator endpoints (for example vialocalStorage.getItem("darkbloom_coordinator_url")andNEXT_PUBLIC_COORDINATOR_URLin provider pages) and then issues browser-sidefetchcalls to that dynamic origin. With this header, any non-default deployment/dev environment will have those requests blocked by CSP, breaking flows like provider dashboard and earnings outsideapi.darkbloom.dev.Useful? React with 👍 / 👎.