当我有两个 CSP(内容安全策略)策略时会发生什么 - header & meta?

What is happening when I have two CSP (Content Security Policies) policies - header & meta?

问题是关于 CSP 服务两次:

如果通过 Content-Security-Policy HTTP 响应 header 提供一个策略,并且还使用 <meta /> 元素指定另一个策略,会有什么行为?

这两者会以某种方式合并吗?或者哪个优先? (我在规范中找不到关于此的明确信息)。

特定用例可能是通过 HTTP 响应 header 服务 Report-to 并将所有其他限制放在 <meta /> 元素中 — 因为其中一些是由 webpack 生成的 — 如果我不应该担心 <meta /> 被 HTTP response-header 政策浅化了。

如果您在 Content-Security-Policy HTTP header 和 meta 元素中都指定了 CSP 指令,则浏览器将在指定的任何位置使用 most-restrictive CSP 指令。

https://w3c.github.io/webappsec-csp/#multiple-policies and details on using the meta element at 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.