Support Rails Content-Security-Policy nonces#542
Open
tuxagon wants to merge 4 commits intoTrestleAdmin:mainfrom
Open
Support Rails Content-Security-Policy nonces#542tuxagon wants to merge 4 commits intoTrestleAdmin:mainfrom
tuxagon wants to merge 4 commits intoTrestleAdmin:mainfrom
Conversation
Despite `stylesheet_link_tag` having a helper, the effort to update sandbox to conform to nonced styles would be major and largely more of a distraction for demonstrating how it works.
Author
|
codeclimate did detect issues, claiming the code to be too similar, but I don't think these methods should be considered such. |
Initially I considered not having an option, but since a nonce generator doesn't care about what's using it from a caller's perspective, it would apply nonces everywhere, even if you didn't want them. These options makes their application a little more explicit and avoids the helper from needing to dig into the Rails config to see if `script-src` or `style-src` are declared to use a nonce.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #529
About
This change adds initial support for Content-Security-Policy provided by Rails. This primarily focuses on nonces which are necessary to avoid
unsafe-inline. For scripts this is more important, but due to the fact that stylesheets can also support this in Rails, it includes those as well.I've also updated the sandbox to enable a content security policy, but I didn't fully enable it for styles because it's quite a task to do "properly" and sandbox is more of an example to showcase Trestle from what I understand.
Testing
If you start the sandbox app and open the dev tools, you shouldn't see any violations. Easiest way to see violations in sandbox is to remove
:unsafe_inlinefrom thestyle-srcdirective and restart the server.Workaround
There is a workaround that can be leveraged at the moment