-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(csp): add collapseHeaders option to experimental CSP #14339
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
base: main
Are you sure you want to change the base?
feat(csp): add collapseHeaders option to experimental CSP #14339
Conversation
Adds `collapseHeaders` option to `experimental.csp` that, when used with experimentalStaticHeaders, consolidates all CSP headers into a single catch-all route, preventing build errors and improving performance for large sites with many routes. - Add collapseHeaders boolean option to experimental.csp configuration - Modify RouteToHeaders population in generate.ts to support header collapsing - Add tests for Vercel, Netlify, and Node adapters - Maintain backward compatibility with existing CSP usage Benefits all adapters that support experimentalStaticHeaders automatically. Reduces config file size from MB to KB for large sites.
🦋 Changeset detectedLatest commit: 19f5098 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
CodSpeed Performance ReportMerging #14339 will not alter performanceComparing Summary
Footnotes |
I'll defer to @ematipico on this as he's leading the feature dev, but I'm in two minds about this. On the one hand I can see the value in something like this, but on the other I'm not sure a catch-all route is the right approach. It's a bit of a blunt instrument and doesn't allow for different directives on different paths. If we do land this, I think it should be called something like |
I also share the same concerns as @ascorbic The 'catch-all' route isn't actually the solution. It could be helpful in most cases, but there may be instances where this approach could lead to issues. For example, the current implementation is a bit naive and it doesn't take into consideration the fact that different pages could emit different headers. We have functions such as Maybe the "catch-all" should work in a way that we catch all routes that have the same headers, and we create the ""catch-all"" for all those routes. It isn't real catch-all, it's a glob that catches all routes that have the same headers. |
Changes
collapseHeaders
option toexperimental.csp
configurationexperimentalStaticHeaders
, consolidates all CSP headers into a single catch-all routeexperimentalStaticHeaders
automatically (Vercel, Netlify, Node)Before: 15k+ individual CSP route entries → 9MB config file → Build failures
After: 1 global CSP route entry → 10KB config file → Successful builds
Reference: #13996 (comment)
Usage:
Testing
experimentalStaticHeaders
using existingstatic-headers.test.js
files for Vercel, Netlify, and Node adapters.collapseHeaders: true
configuration for each adapterDocs
This is a core CSP feature that works universally with all adapters supporting
experimentalStaticHeaders
which affects behavior for large sites experiencing build size limits with CSP enabled.Documentation updates needed for:
collapseHeaders
option in experimental CSP configuration/cc @withastro/maintainers-docs for feedback!