Options for resolution:
1. Use SHA-256 hashes
If there is a relatively small amount of such violations, you can add their hashes.
Example, if you see this in your log:
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' 'report-sample'". Either the 'unsafe-inline' keyword, a hash ('sha256-YpcdPia2p132TdnpnY8zwrWWSqByEKGZBY5iqsLBkSg='), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.
Add 'sha256-YpcdPia2p132TdnpnY8zwrWWSqByEKGZBY5iqsLBkSg='
You may also need 'unsafe-hashes'
- depending on the context.
Note: This approach is not easy to sustain. A small change in a style will force you to recreate the hash. It's useful only when you have a handful of such inline scripts.
2. Nonces
You can use nonces to "bless" inline styles and approve them. However, even Google experts who advocate for CSP nonces don't usually deploy them on style-src
- only on script-src
.
Note: This approach is hard to deploy. A unique nonce needs to be generated for every pageload.
3. Use 'unsafe-inline'
- it's fine for style-src
(not great for script-src
)
Really, even setting a CSP with
style-src 'unsafe-inline' 'self' someurl.com;
is much safer than 99.9% of sites. More than accounts.google.com that does not restrict style-src
at all.
Github have a fantastic high quality CSP with style-src: 'unsafe-inline'
Good luck!