-
-
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
Provide a way to add a nonce to the inline webpack script #5144
Comments
Can the nonce just be a static identifier or does it have to be generated dynamically? |
I'm not sure I understand your question. I don't need CRA to generate the nonce, but just to take a provided nonce and add it to the inline script tag. |
The server must generate a unique nonce for each response (spec), so a nonce based approach would have to be used in combination with custom server configuration, eg: The other option is to add the hash of the inline content to the policy: However given that the webpack runtime chunk changes often (hence why inlining it makes sense), the hash based approach would still need either: |
Does the |
@edmorley The unique nonce requirement does complicate things, especially for a static server. The hash approach does sound better, though I haven't been able to make it work so far. And there is the question of how to feed it back. Would it work to write it to a file in the build folder? @Timer Are you suggesting to add something to index.html to signal that it will be CSP'd? |
Yeah, we could look for |
That would certainly take care of my requirement, but I'm also not familiar with best practices here. |
Since this is an edge case, we recommend you write a #5184 will make sure this file gets emitted to disk ( |
@Timer We just ran into this issue and I read your comment about it. Having implemented a script like the one you suggested, we realised that this might be a rather fragile solution (searching for |
I think we should add an ID to that script. Then you can search by that ID and it should be robust enough. |
@gaearon I like that. If no other scripts pop-up that solution should work 👍 |
What I ended up doing is writing a script that searches for the script and calculates its hash for inclusion in the CSP. But I agree either an ID or, if there may be other scripts in the future, maybe a class, would make it feel less fragile. |
We are also having this issue. It is not an edge case for projects that care about security. I agree with @PerfectPixel that there should be an option to avoid inline scripts and instead reference it as a link. Otherwise, we should at least have an id. |
@Timer @gaearon However, I understand that adding plugins conditionally is not the best way. Or filter missing plugins for that matter. Replacing a plugin with a noop-plugin could also be an option. |
We'd like to avoid adding a configuration flag for this when you can easily patch it with a postbuild script. Let's move discussion to #5288 so it doesn't get lost on this closed issue. |
Version 2.0.0 adds an inline script, which causes a problem with more restrictive content security policies. One way to selectively allow this inline script would be to set a nonce on it, and then whitelist that nonce in the CSP.
I don't know what would be the best way to pass this nonce to the build.
The text was updated successfully, but these errors were encountered: