-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Bug]: Inline styles blocked by CSP style-src
header
#12580
Comments
style-src
header
Thanks for opening this with so much detail! To summarize the situation (let me know if I miss anything):
On our end, one potential way to fix this would be to reduce the usage of inline styles within the components. Unfortunately, the examples you list above are almost all coming from third party flatpickr library. The likelyhood that we're able to completely fix this is low until we revisit datepicker altogether, #11967. In the meantime, it seems a decent workaround to this problem altogether is using a hash to allow inline style attributes. It's safer than doing |
Sup man, so
I think inline styles are blocked no matter what directives are defined, as long as csp is turned on
correct, but nonce and hashing has some limits, (see below)
if i remember correctly, we cannot do any for example, most of console is using nonce, the consumer has to be able to generate it per request and attach it to all there stuff and add it to the policy for hashes, if i remember correctly, you guys generate it but we have to add it for every single page that needs it csp policy which for most is a code change and any changes (or if they are generated differently) will break it i think that works for inline styles, i am a bit rusy on hashing but know some teams have tried it |
@tay1orjones @tw15egan besides the above, found a related issue #12386 |
In that case, the workaround you'll need to explore is how to apply the required (inline) styles yourself via a class instead. I think the primary things that can be tackled here are:
PRs to help out would be much appreciated |
Got ya, if I figure out more or a better way to help I will let y'all know!
|
I've added a task list to the issue body containing the components using inline styling. It includes a task to determine if we can reduce/remove inline styling stemming from third party libraries like flatpickr (there may be others - downshift?) |
This would improve the situation greatly, but there's been no movement -w3c/webappsec-csp#174 |
The issue with this is all teams who use anything with unsafe have to get pce exception and get it fixed by a date
|
Another way we could set styles dynamically would be to use CSSOM, which should be compatible with CSP. Instead of rendering an inline style like this <div id="test" style="left: 300px;"/> we could instead set it imperatively via document.getElementById('test').style.left = '300px'; |
Hey there! checking in from the carbon-for-ibmdotcom side of things and CSSOM totally works. Per MDN:
As an example, here's a quick codepen |
Hi. Was wondering if the groups on this ticket had any luck with SVGs and their inline stuff for their products. We are running into issues with the pictograms. So wondering if your products found a work around. Happy to connect via slack as well ((at)david) |
@andy-blum or @TannerS have either of you encountered and had to resolve issues with SVGs or the pictograms and CSP? |
Which styles specifically are in an inline attribue? Could you move them to their own specific attributes? For example, instead of
You could do
|
It seems to be however the SVG are made (some seem good. Some have issues). I assume most came from designers and just converted to react components. Updating all to be attributed instead of inline would be the solution. But a bit of a painful one for migrating all the SVGs. So was just wondering if any better options appeared. |
Not particularly. Inline styles are only allowable under a CSP if you know the exact markup beforehand and can pass a hash in with the CSP directive headers |
Package
@carbon/react
Browser
Chrome, Firefox
Package version
^1.5.0
React version
v17
Description
Background
IBM console / cloud has started to implement the CSP header ( https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP ). Part of that is it blocks inline styles,
will be blocked unless it has a
nonce
value passed in by the consumerwhere
<div style=....></div>
will be blocked no matter what
this is problematic since all of ibm cloud ios moving to CSP, some inline styles (second example) will be blocked by CSP and break the component to some limit.
Here is some that I personally searched for and found in the carbon repo (click to expand)
DatePicker
with csp
without
This one for some reason doesnt give me a warning but if you look here theres a style property that gets added (i changed it to height to show an example)
but csp can affect browsers differently so it should be something to look into
SkeletonText / Slider / ProgressBar
These also have inline styles that may be blocked by csp so worth a look
Other
Suggested Severity
Severity 3 = User can complete task, and/or has a workaround within the user experience of a given component.
Reproduction/example
N/A
Steps to reproduce
I am testing on my local microservice for ibm cloud with csp to verify
DatePicker
Code of Conduct
#12580 (comment)
The text was updated successfully, but these errors were encountered: