Warm tip: This article is reproduced from serverfault.com, please click

Firefox gives an error with a CSP policy that shouldn't happen

发布于 2020-11-27 18:55:44

A firefox addon with the following csp in the sidebar html document: <meta http-equiv="Content-Security-Policy" content="style-src *;">

Gives this error with a <style></style> embedded in the same html document of that policy

Error:

Content Security Policy: The page’s settings blocked the loading of a resource at inline (“style-src”).

I get the same error with "style-src 'self';" or "default-src *;" or etc, it only works when i dont use default-src or style-src

This shouldn't happen so please tell me if i missed something

Thanks for your time

Questioner
user10156126
Viewed
0
granty 2020-11-28 13:31:44

'self' and * allow external sources only (ie <link href='https://example.com' rel='stylesheet'>).
To allow inline styles requires 'unsafe-inline' or 'nonce-value' token. For example:

<meta http-equiv="Content-Security-Policy" content="style-src 'nonce-abcFe45';">

and in the HTML:

<style nonce="abcFe45">
...
</style>

Or <meta http-equiv="Content-Security-Policy" content="style-src 'unsafe-inline';"> will allow any inline <style></style> blocks and <tag style='color:red'> too.