HTTP标头和元标记中都包含Content-Security-Policy的问题

问题描述 投票:0回答:1

我们正在研究一个Web项目,其中通过HTTP标头和元标记也实施了内容安全策略。有一组默认属性,这些属性是HTTP标头的一部分,并且每个页面都通过文档标头中的meta标记指定其他策略。

项目中的页面之一将内容加载到iframe中。该页面的HTTP标头中的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。尽管在HTTP标头中设置了frame-src,但在浏览器控制台中仍收到以下错误消息(在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.

也,

将两个策略都移至HTTP标头或元标记按预期工作

http browser http-headers cross-domain content-security-policy
1个回答
0
投票

Content Security Policy上frame-src上方的更一般的页面解释了您所看到的内容:

多内容安全策略

CSP允许为资源指定多个策略,包括通过Content-Security-Policy标头,Content-Security-Policy-Report-Only标头和<meta>元素。

您可以多次使用Content-Security-Policy标头...添加其他策略只能进一步限制受保护资源的功能。

因此,对于多个CSP,就像它们都在起作用not,就像您看到的那样,它们被组合为一个组合策略。因此,在您的示例中,您实际上将frame-src设置为none(因为您具有default-src且没有针对frame-src的特定替代),因此稍后打开它不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.