问题是关于拥有 CSP送达两次:
如果有一个通过 Content-Security-Policy
提供的策略会发生什么行为? HTTP 响应 header 以及使用 <meta />
指定的另一个策略元素?
这两者会以某种方式合并吗?或者哪个优先? (我在规范中找不到关于此的明确信息)。
特定用例可能正在服务 Report-to
通过 HTTP 响应 header 并将所有其他限制放在 <meta />
中元素——因为其中一些是由 webpack 生成的——如果我不应该担心 <meta />
被 HTTP 响应头策略淡化。
最佳答案
如果您在 Content-Security-Policy
中同时指定了 CSP 指令HTTP header 和 meta
元素,浏览器使用最严格的 CSP 指令,无论在哪里指定。
在 https://w3c.github.io/webappsec-csp/#multiple-policies 上查看多个策略的详细信息以及使用 meta
的详细信息https://w3c.github.io/webappsec-csp/#meta-element 处的元素:
A policy specified via a
meta
element will be enforced along with any other policies active for the protected resource, regardless of where they’re specified. The general impact of enforcing multiple policies is described in §8.1 The effect of multiple policies.8.1. The effect of multiple policies
The impact is that adding additional policies to the list of policies to enforce can only further restrict the capabilities of the protected resource.
关于security - 当我有两个 CSP(内容安全策略)策略 - header 和元时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51148998/