gpt4 book ai didi

http - Content-Security-Policy 如何与 X-Frame-Options 一起使用?

转载 作者:可可西里 更新时间:2023-11-01 15:05:24 35 4
gpt4 key购买 nike

Content-Security-Policy 是否忽略服务器返回的 X-Frame-Options,或者 X-Frame-Options 仍然初级?

假设我有:

  • 一个网站 http://a.com使用 X-Frame-Options: DENY
  • 和一个网站 http://b.com使用 Content-Security-Policy: frame-src a.com

浏览器会加载这个框架吗?

不清楚。
一方面,http://a.com明确拒绝框架。
另一方面,http://b.com明确允许 http://a.com 的框架.

最佳答案

frame-src CSP directive (已弃用并由 child-src 取代)决定了页面框架中可以使用哪些来源。

另一方面,X-Frame-Options 响应 header 确定哪些其他页面可以在 iframe 中使用该页面。

在您的情况下,http://a.comX-Frame-Options: DENY 表示没有其他页面可以在框架中使用它。 http://b.com 在其 CSP 中有什么并不重要——任何页面都不能在框架中使用 http://a.com


X-Frame-Options 与 CSP 相交的地方是通过 frame-ancestors directive .来自CSP specificiation (强调我的):

This directive is similar to the X-Frame-Options header that several user agents have implemented. The 'none' source expression is roughly equivalent to that header’s DENY, 'self' to SAMEORIGIN, and so on. The major difference is that many user agents implement SAMEORIGIN such that it only matches against the top-level document’s location. This directive checks each ancestor. If any ancestor doesn’t match, the load is cancelled. [RFC7034]

The frame-ancestors directive obsoletes the X-Frame-Options header. If a resource has both policies, the frame-ancestors policy SHOULD be enforced and the X-Frame-Options policy SHOULD be ignored.

older question表示当时这在 Firefox 中不起作用,但希望现在情况有所改变。


2018 年 4 月更新:

Content Security Policy: Directive ‘child-src’ has been deprecated. Please use directive ‘worker-src’ to control workers, or directive ‘frame-src’ to control frames respectively.

看起来 child-src 现在已被弃用,frame-src 又回来了。

关于http - Content-Security-Policy 如何与 X-Frame-Options 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40373771/

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