You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support CSP Restrictions Without Nonce Attribute (IE11) #1137
I have a project that I would like to explore using a css-in-js library such as styled-components.
However, the Content-Security-Policy restrictions for this project are such that style tags are not allowed to be injected onto the page, and must be served in the initial static html file.
One solution around this would be to provide a nonce attribute. Styled components accomplishes this through an undocumented feature of webpack (See Issue).
I've created a minimal server example that should (theoretically) produce the same CSP restrictions for loading styles.
There may be another way around these CSP settings that are equally as secure, but allow for dynamic styles from a trusted source such as glamor. But I am not aware of any. (I'm also not an expert in CSP 😞 )
I suppose one way around this would be to somehow statically analyze the styles and generate a stylesheet at build time. However, I think we would lose out on one of the very powerful features of styled-components and related libraries: dynamically re-defining styles based on props, state, and theming.
I suppose one way around this would be to somehow statically analyze the styles and generate a stylesheet at build time. However, I think we would lose out on one of the very powerful features of styled-components and related libraries: dynamically re-defining styles based on props, state, and theming.
We currently don't have any SSR implemented on this project, and I don't believe it's a priority for the team at the moment. I'm not sure the team could be convinced that s-c or another css-in-js lib will provide enough of an improved development experience to offset the setup and maintenance of a SSR solution.
However, I'm open to suggestions! If there is something we can do at build time, for example, I'm very open to those possibilities.
So I've just read up on IE 11 not supporting CSP except HTML 5 Sandbox. I don't think IE 11 would even block anything, since it doesn't support any of the directives anyway. So where does this concern stem from, when IE 11 clearly doesn't support it anyway?
However, the Content-Security-Policy restrictions for this project are such that style tags are not allowed to be injected onto the page, and must be served in the initial static html file.
I don't really see how we can support CSP without SSR, when CSP is literally not (barely, but for all intents and purposes not at all) supported in the first place?
I'm not too familiar with all its concepts, but I don't really know what your goal is then unfortunately?
I don't want to come across to harsh, sorry 😉 But if you don't have any server-side rendering and want to avoid any injection w/o the CSP in place, there's not really anything we can do, is there not?
Activity
kitten commentedon Sep 3, 2017
This will generally not be possible, even with v3, for various reasons. I've compiled a document that sums up the problems since it has come up repeatedly: https://gist.github.com/philpl/7b8a021f19ead2ec534091976a1ff6dc#file-2-specificity-md
I don't think there'll be an easy way around. However, can we at least fix the problem with SSR somehow for IE11?
[-]Support CSP Restrictions Without Nonce Attribute[/-][+]Support CSP Restrictions Without Nonce Attribute (IE11)[/+]arahansen commentedon Sep 3, 2017
We currently don't have any SSR implemented on this project, and I don't believe it's a priority for the team at the moment. I'm not sure the team could be convinced that s-c or another css-in-js lib will provide enough of an improved development experience to offset the setup and maintenance of a SSR solution.
However, I'm open to suggestions! If there is something we can do at build time, for example, I'm very open to those possibilities.
kitten commentedon Sep 3, 2017
So I've just read up on IE 11 not supporting CSP except HTML 5 Sandbox. I don't think IE 11 would even block anything, since it doesn't support any of the directives anyway. So where does this concern stem from, when IE 11 clearly doesn't support it anyway?
I don't really see how we can support CSP without SSR, when CSP is literally not (barely, but for all intents and purposes not at all) supported in the first place?
I'm not too familiar with all its concepts, but I don't really know what your goal is then unfortunately?
I don't want to come across to harsh, sorry 😉 But if you don't have any server-side rendering and want to avoid any injection w/o the CSP in place, there's not really anything we can do, is there not?
geelen commentedon Sep 3, 2017
Yeah from my understanding IE11 won't block the inline stylesheets at all, right? Its implementation of CSP doesn't do that... I think??
arahansen commentedon Sep 3, 2017
Wow, @geelen you're totally right. MDN even lists
style-srcas "no support" for IE. I guess I never looked there 😅. I think this answers my question. Thanks guys!