This repository has been archived by the owner on May 3, 2024. It is now read-only.
fix(csp): remove script nonce if inline scripts are disabled #700
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The changes made in #636 are breaking due to the script nonce being added to the initial response, even if the environment variable is enabled and it is being correctly suppressed from the CSP header.
Description
The middleware that prepares the HTML response already includes a check to not apply the script nonce if it isn't populated, so we just need to ensure that the nonce is never populated if inline scripts are enabled in dev, rather than simply suppressing it in the header. I've moved the code applying up slightly inside the conditional blocks that run either in production, or if the env var isn't set.
I tested this feature using a root module, and it only occurs if the app's root module is a prod build and not being served, and so overlooked this scenario.
Motivation and Context
Bugfix for #636
This bug only occurs if you aren't serving your app's root module. In OneApp 5.13 you can avoid it by serving your root module.
How Has This Been Tested?
I tested it with a child module this time, in Firefox 97.0.2.
Types of Changes
Checklist:
What is the Impact to Developers Using One App?
Feature added in #636 works in all scenarios