在内容安全策略的上下文中,可以有从策略中排除的元素,如果它们具有 nonce
相应政策中指定的属性。
显然这适用于某些 HTML 元素,例如<script nonce="...">
和 <style nonce="..."
.然而,对于某些人来说,它不起作用,例如 <iframe nonce="..." >
.
在 MDN Documentation写的是提示:
Note: The CSP
nonce
source can only be apply nonceable elements (e.g. as the<img>
element has nononce
attribute, there is no way to associate it with this CSP source).
是否有完整的 nonceable 元素列表?
MDN 列出了
nonce
脚本和样式标签的属性。另一方面nonce
<link>
的属性未列出元素,但无论如何都可以。还有更多这样的元素吗?附带问题:为什么是
<img>
和 <iframe>
不是不可取的?
最佳答案
In the MDN Documentation is written the hint:
Note: The CSP nonce source can only be apply nonceable elements (e.g. as the <img>
是的,同时 Firefox v52.9 版本 25/06/2018 支持<img>
的随机数,<iframe>
,<object >
,<embed>
,<audio>
和<video>
.如果您有 WinXP PC,您可以 ensure that .
如上面的测试所示,目前只有<style>
和<script>
是 nonceables,即使 CSP3 不限制对任何 HTML 元素使用 nonce。
关于html - 哪些 HTML 元素是不可分割的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65693187/