-
-
Notifications
You must be signed in to change notification settings - Fork 51
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 support for inline JS inserted via content-for #149
Comments
Thanks a lot for this great summary. There is already something similar to the proposed strategy. The addon adds a nonce to a code tag added by Ember CLI for builds that contain tests: https://github.com/rwjblue/ember-cli-content-security-policy/blob/43527edab59a68c8d747fede8cae4573d352baf2/index.js#L278-L285 This prevents that a newly generated ember project violates the default CSP. The approach proposed here would provide a public API, which covers this case. So it would reduce complexity. It would have to additional benefits:
|
It maybe helpful to document why I think assuming that elements added via Security considerationsThe approach discussed above would treat all inline script (and styles) added via I think this is acceptable from a security perspective cause of these arguments:
I think that CSP does not help if you don't trust your build. |
Haven't read things in detail just yet, but leveraging the |
This proposal is only about supporting addons out of the box, which use // index.js of some addon
module.exports = {
contentFor(type) {
return '<script>window.alert("This code will violate a default CSP")</script>';
}
} As far as I know there isn't a similar capability in v2 addon format (Embroider) yet. If one is added later we can explore if a similar zero-config solution for addons using that capability is possible as well. We could maybe even consider that feature when designing such a capability. |
@jelhan just pointed me to this issue. Wanted to bring in some context to support this case, but also to include support for inline So in our case, However when using We fixed this by manually adding the hash for all inline styles to our CPS policy, but this proposed feature - when including styles support - would have helped here! |
Is there any workaround for this? This seems like a similar issue to #67 and we are hitting this in ember-electron. We use |
There isn't a good work-a-round for addons. 😞 Addons can not modify the CSP of a consuming application. If I didn't missed something they only have two options:
A |
Why?
Addons, such as
ember-svg-jar
, inserts an inline JS. The inline JS generally violates the CSP script-src directive unless one of the following sources are added to the directive:unsafe-inline
Nonce
Nonce is added to the
<script>
tag as an attribute, as well as in the CSP script-src directive, and needs to be unique for each page request.For SPA's that are not backed by server-side rendering, a unique nonce-value won't be generated each time.
Hash
A hash is generated from the contents of the script tag, including all whitespace and line breaks.
unsafe-inline
This defeats the purpose of the CSP script-src, which would allow any inline JS to load.
Proposal
Generate a hash for every inline JS, and maybe CSS, and add it to the corresponding CSP directive at build time.
From a discussion with @jelhan:
The text was updated successfully, but these errors were encountered: