gpt4 book ai didi

http - 当 HTTP header 和元标记中同时存在 Content-Security-Policy 时出现问题

转载 作者:行者123 更新时间:2023-12-03 08:48:24 30 4
gpt4 key购买 nike

我们正在开发一个 Web 项目,其中内容安全策略是通过 HTTP header 和元标记强制执行的。有一组默认属性,它们是 HTTP header 的一部分,每个页面通过文档 header 中的元标记指定附加策略。

项目中的一个页面加载 iframe 内的内容。该页面的 HTTP header 中的 Content-Security-Policy 为

Content-Security-Policy: frame-src *;

页面的文档标题中有以下元标记

<meta http-equiv="Content-Security-Policy" content="default-src none;"/>

MDN Web Docs中提到后备顺序是 frame-src -> child-src -> default-src 。尽管设置frame-src在 HTTP header 中,我在浏览器控制台中收到以下错误消息(在 Google Chrome 和 Microsoft Edge 上尝试过):

Refused to frame '<url here>' because it violates the following Content Security Policy directive: "default-src none". Note that 'frame-src' was not explicitly set, so 'default-src' is used as a fallback.

另外,

Moving both the policies either to the HTTP header or to the meta tag works as expected

最佳答案

Content Security Policy 上的frame-src 之上的更通用的页面解释您所看到的内容:

Multiple content security policies

CSP allows multiple policies being specified for a resource, including via the Content-Security-Policy header, the Content-Security-Policy-Report-Only header and a <meta> element.

You can use the Content-Security-Policy header more than once... Adding additional policies can only further restrict the capabilities of the protected resource.

因此,对于多个 CSP,就像所有这些都在发挥作用,并且,正如您似乎想要的那样,它们被合并为一个组合策略。因此,在您的示例中,您实际上拥有 frame-src设置为none (因为您有 default-src 并且没有针对 frame-src 的特定覆盖),因此稍后打开它不起作用。

关于http - 当 HTTP header 和元标记中同时存在 Content-Security-Policy 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60465220/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com