-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Possible to add a noonce option for scripts? #3746
Comments
I tried it here: https://github.com/zionis137/gatsby/commit/3c260c62ca0706294cf52ed975edace4753bfc72 As I don't have much time this week feel free to take it and make a PR. |
I misunderstood how nonce works. It needs to be generated by the server on each http request. This may not be the best approach upon re-thinking this problem. I'm going to close this and try to come up with a better solution. |
sure, For static sites Hashes are the better alternative #3427. |
Using nonce for CSP requires a server to generate the nonce for every request. From: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
Also, code can be injected without needing to touch the server. XSS attack as follows
This attack and others can be completely mitigated with a good CSP. I'd recommend starting with
and the relaxing the policy from the as needed. The SHA approach is definitely better. |
For anyone stumbling across this now closed issue... I'd go a step further and advocate defaulting to A good article worth checking out (a fews years old now, but still very valid): https://github.blog/2016-04-12-githubs-csp-journey/ |
We still need a solution to this since Google Tag Manager and Analytics otherwise require 'unsafe-inline' |
Seems odd to me that this is closed. Not being able to generate a nonce on each request -- hashes don't work with gtm because the scripts seem to change on every load -- basically means that anyone using google tag manager (or any other tool that dynamically injects scripts on load) and needs a secure Content security policy can't use Gatsby. I have to think that is a lot of websites! |
Would it be possible to add a
nonce
option to Gatsby as a whole or to plugins such as Google Analytics individually? This could possibly help issue #3427 & allow people to use Content Security Policies with inline scripts protected.If this is something that makes sense, I would be happy to try & create some pull requests.
The text was updated successfully, but these errors were encountered: