-
-
Notifications
You must be signed in to change notification settings - Fork 1
fix: usage with CSP and nonce #8
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?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@elliott-with-the-longest-name-on-github could you have a look at this? |
Oh shoot, thanks for the tag, and thanks for the PR! I'll do my best to get to this ASAP, but I have three days before vacation and a lot of stuff to get done. But I won't let it die! |
Thanks for message! No worry and no rush! |
I'm struggling a bit with this, actually. First, from a UX perspective, using Second, this is not a safe use of nonce. I ported it over from the Next version, but that one is unsafe too. Basically, what you're saying is: "Inject this third-party script from NPM into my application, and sign it as secure." If this library were to be compromised, it could then inject signed, trusted scripts into any app using the latest version. (Also, if someday I become a villain, I could thoroughly screw anyone using this library.) The correct way to do this from the end of the consumer is to create a hash of the script we embed and add that to |
Ugh yeah, that doesn't work either because of the dynamic script attributes and arguments. Duh. Let me think on this a little more... |
Thanks for having a look!!
Glad I'm not the only one.
I wasn't aware of that (as we don't use prerendering), but that makes total sense and is not ideal. But that is also true if CSP is used without the head script, but for the other js code that is bundled, or how does this work?
You're absolutely right. However, whether your code is inserted via a The way I see it, CSP (with
That could be a solution to the That said, I think the current implementation in this PR offers the same security as importing this library in the first place. What do you think would be the cleanest way forward? |
Reading about it, what you might have been thinking about is Subresource Integrity (SRI)
But that's for including scripts from a CDN, not bundled dependencies like this library here. And reading about prerendering and CSP with I think the current PR is architectually as convenient as it gets for using CSP with SvelteKit. The security regarding third-party code stays the same (users need to trust you and or review all updates) and overall it's increased due to the use of the CSP which protection against XSS. The way I implemented it (with What do you think? |
This PR provides a way make this library work with a content security policy and SvelteKit's way of adding nonces to scripts in app.html.
I tried to make it possible with the least changes to the existing code and invisible to users without CSP.
ThemeProvider
to disable head script injectiondom.ts
andhead-script.svelte
scriptAsString
fromdom.ts
fixes: #7