如何允许脚本添加内联CSS而不允许`unsafe-inline` CSP?

时间:2019-07-14 23:25:17

标签: content-security-policy

我正在尝试将第3方聊天窗口小部件脚本加载到我的网站上。该脚本尝试添加内联样式来设置小部件样式。我收到此错误

Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' fonts.googleapis.com 1234.example.com". Either the 'unsafe-inline' keyword, a hash ('sha256-12345='), or a nonce ('nonce-...') is required to enable inline execution.

我当前的CSP是:

CSP_STYLE_SRC = ("'self'", 'fonts.googleapis.com', '1234.example.com',)
CSP_SCRIPT_SRC = ("'self'", '1234.example.com',)

通常情况下,我可以在CSP中加载随机的第三方脚本/样式。我如何告诉我的CSP我要允许此JS文件添加内联样式?我现在所拥有的不起作用。

这个问题是多年前here提出的。我不想允许不安全的路线。我相信除了将CSS组件从JS文件中分离出来并将它们移至单独的CSS文件之外,没有其他解决方案。

0 个答案:

没有答案