-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Add an ID to the run time script #5288
Comments
@Timer I understand that adding a Example: The solid solution is to parse the If more scripts are inlined, this solution will break as well. I completely understand the desire to not create additional environment variables or configuration options as they surely add complexity. But in this case it is essentially punishing users that try to maintain a high security standard - regardless if they want to do it or are even (legally) obligated to do so). I can absolutely understand that saving one additional request for a small file is worth it. But while going from I do not intend to press this any further, I just do not think this is really a small edge-case. Thank you for your time & feedback 👍 |
Just for comparison, Angular CLI has always extracted the script to a separate file precisely for this issue. Before v6 it was even called somewhat confusingly |
This is a slightly off-topic comment but I do wonder if it's even a good thing to inline the JavaScript at all in the HTTP2 era. It makes it impossible to make the JS code async and if the .js file is served on the same domain there is extremely little overhead to serving it as a file over HTTP2. The HTML can be parsed sooner because it's smaller which means it can get started, in parallel, to download (and start parsing) other assets. Would love to see a simple option to disable all inlining. Also, because #5144 is now closed I'll post it here: If others are struggling with busted Content Security Polices as of this recent change, you might get some inspirational ideas from this blog post: https://www.peterbe.com/plog/inline-scripts-in-create-react-app-2.0-and-csp-nonces |
I could be wrong, but I believe that using a static |
@edmorley You're right. I rushed that. Fixed my blog post now. But also, I changed my mind about bothering anyway. I took @PerfectPixel 's heed and wrote a script that "uninlines" the inline script tag. |
Thanks @peterbe, that looks quite helpful. Although it seems quite insane the hoops you have to jump through just to get back to where we were with CRA1. This change only encourages a less secure web - with less experienced/lazy devs most likely to just turn off CSP or allow |
@Timer Where should we redirect our issues about A) an option to disable inlining small scripts and B) lobby to have that option "on" by default. |
This issue, @peterbe. |
I say let’s add a way to opt out. #5309 (comment) I still think the majority would be better served by the inlined script though. |
We can close this if we're going to add an environment variable. |
Any update on this? I'd like to see the webpack config for inlining the runtime chunk be opt-in. IMHO having this inlined is a premature optimization at the cost of easily serving the app with a sane CSP. The only other option to prevent having |
@jvatic you can opt out with |
Or add a config override, like |
a little ugly, but it's probably fine to do: function serveApp(res) {
const nonce = crypto.randomBytes(16).toString('base64');
res.set({
'Content-Security-Policy': `....; script-src 'nonce-${nonce}'`,
// ..
});
return fs.promises.readFile(path.join(__dirname, 'static', 'myapp', 'index.html'), 'utf8')
.then(indexHtml => res.send(indexHtml.replace(/<script>/g, `<script nonce="${nonce}">`)));
} (coming from #5144 nonce issue) edit: actually using INLINE_RUNTIME_CHUNK=false is better (seen it in https://deploy-preview-27627--material-ui.netlify.app/guides/content-security-policy/#create-react-app-cra) |
Re #5144 the problem is not only for the runtime script, but also for lazy-loaded scripts, what can we do with react-scripts? |
#5144 (comment)
The text was updated successfully, but these errors were encountered: