question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: Inline styles blocked by CSP `style-src` header

See original GitHub issue

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,

<style>
// css here
<style>

will be blocked unless it has a nonce value passed in by the consumer

where

<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 image

without image

image

image

image

image

image

image

image

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)

image

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

image

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

https://github.com/carbon-design-system/carbon/issues/12580#tasklist-block-a9785d44-ab13-438b-8bb3-d2ba230a2a72

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
andy-blumcommented, Dec 1, 2022

Hey there! checking in from the carbon-for-ibmdotcom side of things and CSSOM totally works.

Per MDN:

Inline style attributes are also blocked:

<div style="display:none">Foo</div>

As well as styles that are applied in JavaScript by setting the style attribute directly, or by setting cssText:

document.querySelector('div').setAttribute('style', 'display:none;');
document.querySelector('div').style.cssText = 'display:none;';

However, styles properties that are set directly on the element’s style property will not be blocked, allowing users to safely manipulate styles via JavaScript:

document.querySelector('div').style.display = 'none';

As an example, here’s a quick codepen

0reactions
TannerScommented, Dec 1, 2022

That may still trigger csp I think (think being the word) but diff will need to be tested

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Taylor Jones @.> Sent: Thursday, December 1, 2022 9:04:21 AM To: carbon-design-system/carbon @.> Cc: Tanner Summers @.>; Author @.> Subject: Re: [carbon-design-system/carbon] [Bug]: Inline styles blocked by CSP style-src header (Issue #12580)

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’;

— Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcarbon-design-system%2Fcarbon%2Fissues%2F12580%23issuecomment-1334077662&data=05|01||815d8a07d90c4780c47008dad3be1786|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|638055110632849967|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|3000|||&sdata=5OVnRYaIFWBLAkx5e1uIPN920N0HXbsueV502By%2FMas%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACDUUDYJDNZWASICOQDXQYTWLDLBLANCNFSM6AAAAAAR2W26BQ&data=05|01||815d8a07d90c4780c47008dad3be1786|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|638055110632849967|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|3000|||&sdata=Ssa2L%2FZTP2Evs89vyZjX%2BvDQO%2FT8GWY7%2Fvc%2FUaGCULA%3D&reserved=0. You are receiving this because you authored the thread.Message ID: @.***>

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSP Allow Inline Styles - Content Security Policy
Inline Styles are Blocked by Default with Content Security Policy. When you have a Content-Security-Policy header defined, the browser will automatically ...
Read more >
CSP: style-src - HTTP - MDN Web Docs - Mozilla
To allow inline styles, 'unsafe-inline' , a nonce-source or a hash-source that matches the inline block can be specified.
Read more >
"inline-style"-Error with Content Security Policy and Javascript
Old Answer: According to the MDN documentation on CSP you can solve it by sending the following header: style-src 'unsafe-inline' ...
Read more >
Inline styles in Next 10 don't work with strict Content-Security ...
Bug report Describe the bug Recent versions of Next are using inline styles, which break our apps because we block style-src: unsafe-inline ...
Read more >
Content Security Policy blocks inline execution of scripts and ...
The Content Security Policy (CSP) prevents cross-site scripting attacks by blocking inline execution of scripts and style sheets. To solve this, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found