CSP: frame-ancestors - HTTP 编辑

The HTTP Content-Security-Policy (CSP) frame-ancestors directive specifies valid parents that may embed a page using <frame>, <iframe>, <object>, <embed>, or <applet>.

Setting this directive to 'none' is similar to X-Frame-Options: deny (which is also supported in older browsers).

CSP version2
Directive typeNavigation directive
default-src fallbackNo. Not setting this allows anything.
This directive is not supported in the <meta> element.

Syntax

One or more sources can be set for the frame-ancestors policy:

Content-Security-Policy: frame-ancestors <source>;
Content-Security-Policy: frame-ancestors <source> <source>;

Sources

<source> can be one of the following:

The frame-ancestors directive’s syntax is similar to a source list of other directives (e.g. default-src), but doesn't allow 'unsafe-eval' or 'unsafe-inline' for example. It will also not fall back to a default-src setting. Only the sources listed below are allowed:

<host-source>
Internet hosts by name or IP address, as well as an optional URL scheme and/or port number, separated by spaces. The site's address may include an optional leading wildcard (the asterisk character, '*'), and you may use a wildcard (again, '*') as the port number, indicating that all legal ports are valid for the source. Single quotes surrounding the host are not allowed.
Examples:
  • http://*.example.com: Matches all attempts to load from any subdomain of example.com using the http: URL scheme.
  • mail.example.com:443: Matches all attempts to access port 443 on mail.example.com.
  • https://store.example.com: Matches all attempts to access store.example.com using https:.

If no URL scheme is specified for a host-source and the iframe is loaded from an https URL, the URL for the page loading the iframe must also be https, per the W3C spec on matching source expressions.

<scheme-source>
A scheme such as http: or https:. The colon is required and scheme should not be quoted. You can also specify data schemes (not recommended).
  • data: Allows data: URIs to be used as a content source. This is insecure; an attacker can also inject arbitrary data: URIs. Use this sparingly and definitely not for scripts.
  • mediastream: Allows mediastream: URIs to be used as a content source.
  • blob: Allows blob: URIs to be used as a content source.
  • filesystem: Allows filesystem: URIs to be used as a content source.
'self'
Refers to the origin from which the protected document is being served, including the same URL scheme and port number. You must include the single quotes. Some browsers specifically exclude blob and filesystem from source directives. Sites needing to allow these content types can specify them using the Data attribute.
'none'
Refers to the empty set; that is, no URLs match. The single quotes are required.

Examples

Content-Security-Policy: frame-ancestors 'none';

Content-Security-Policy: frame-ancestors 'self' https://www.example.org;

Specifications

SpecificationStatusComment
Content Security Policy Level 3
The definition of 'frame-ancestors' in that specification.
Working DraftNo changes.
Content Security Policy Level 2
The definition of 'frame-ancestors' in that specification.
RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:106 次

字数:7156

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文