首页 > 解决方案 > CSP 规则以不同方式应用于 Firefox 中的 SVG

问题描述

我有带有内容安全策略的 HTML 文档。

<meta http-equiv="Content-Security-Policy" content="style-src 'self'">

我创建 SVG 元素,设置style属性并将元素附加到文档中。

const el = document.createElementNS('http://www.w3.org/2000/svg', 'svg');

el.style.background = 'green';
document.body.appendChild(el);

在 Firefox 中,我收到内容安全策略错误,并且未应用样式。Chrome 中没有错误。Firefox 中的 DIV 元素没有错误。

这种行为是预期的还是实现错误?


下面的演示应该在 Chrome 中显示两个绿色框。在 Firefox 中,右边的框是红色的。

https://pste.eu/p/gKqO.html

标签: javascriptfirefoxsvgcontent-security-policy

解决方案


推荐阅读