Apply CSP nonce when createElement is called
See original GitHub issueHi!
Firstly, thanks for your work on this project! 👋
Today I used patch-package to patch @hotwired/turbo@7.1.0
for the project I’m working on.
There is an issue which is documented here https://github.com/hotwired/turbo/pull/501/files but that fix doesn’t exist in this file.
Here is the diff that solved my problem:
diff --git a/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js b/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
index 963422f..1b164fe 100644
--- a/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
+++ b/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
@@ -1215,6 +1215,9 @@ class ProgressBar {
const element = document.createElement("style");
element.type = "text/css";
element.textContent = ProgressBar.defaultCSS;
+
+ element.nonce = document.head.querySelector('meta[name="csp-nonce"]')?.getAttribute('content')
+
return element;
}
createProgressElement() {
This issue body was partially generated by patch-package.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
FAQ - Content Security Policy
Method #1: Use CSP hashes instead of nonces. It's possible to calculate SHA hashes of static inline <script> blocks with this tool, or...
Read more >CSP: script-src - HTTP - MDN Web Docs - Mozilla
The HTTP Content-Security-Policy (CSP) script-src directive specifies valid sources for JavaScript. This includes not only URLs loaded ...
Read more >CSP Nonce Examples and Guide - Content Security Policy
A nonce is a randomly generated token that should be used only one time. What is a nonce? The word nonce can be...
Read more >Use Tag Manager with a Content Security Policy
Enable the container tag to use CSP ... Tag Manager will then propagate the nonce to any scripts that it adds to the...
Read more >Mitigate cross-site scripting (XSS) with a strict Content Security ...
A Content Security Policy based on nonces or hashes is often called a strict CSP. When an application uses a strict CSP, attackers...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Unfortunately, the file doesn’t contain any helpful comments. But I’ll find out anyway 😉 But thank you very much for your help. I think we are done here, as the initial issue with turbo.es2017-esm.js is resolved by your fix.
Here’s what I could suggest you to do
loadWidgetCss.js
- you’ll probably see a code that is building style tag.element.nonce = ''
loadWidgetCss.js
- take a look at top of this file - maybe you’ll find information where does it come from