When setting the content security policy directive
style-src 'self' 'nonce-{NONCE_GOES_HERE}
for my web app, I expected that inline styles added using the style
attribute would not be applied. However, despite receiving error messages about CSP violations for each inline style, the styles are still being applied.
This same issue occurs when using the style-src-attr
directive in recent versions of Chrome, Firefox, Edge, and Safari. Is this behavior expected? If so, is it documented anywhere (considering the CSP spec indicates otherwise)?
UPDATE: This problem is reproducible in React. The directives work as intended with plain HTML+CSS. Here are some examples:
To reproduce the issue:
- Create a React app that contains a component with a
style
property. - The
<head>
of the webpage should include a<meta>
tag with a CSP that does not allow inline styles (unsafe-inline
). For example:
<meta http-equiv="Content-Security-Policy" content="style-src 'self' 'nonce-bm9uY2U='" />
<meta http-equiv="Content-Security-Policy" content="style-src-attr 'none'" />