-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[feat] Add nonce placeholders in rendered pages. #2391
Conversation
🦋 Changeset detectedLatest commit: cc1618b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Thanks for this! Can you add some docs in https://github.com/sveltejs/kit/tree/master/documentation/docs showing how it would be used? |
Sure! I'll write it up! I'm not sure if I'm really in love with this solution though. Would it be better to do something more akin to what Sapper did and generate the nonce in Kit itself and make it available to hooks in
Should we not be using built-in node modules in this part of the app? It works in |
I've created an alternative at #2394 which generates and inserts nonces instead of just a placeholder. It seems like a better overall solution to me, but I'm keeping both PRs open so maintainers can choose the best option. |
I'm closing this in favour of #2394. We can come back to this concept if that one doesn't work out. |
Related to #93
Adds a CSP nonce placeholder to all script and style tags if
config.kit.noncePlaceholders
is true. This allows a hook to easily replace them with a nonce alongside where they are likely already inserting the CSP headers themselves.As currently configured this supports
'strict-dynamic'
(that's why the nonce is added to all scripts, not just the inline init script).Note that this only works on dynamic hosts. Nonces can't be used in a static environment.
This will need documentation somewhere; I'm open to doing that if someone points me to where to place it :) Particularly an example of a CSP hook would be good.
Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0