Skip to content

Directive: frame ancestors

Ryan Parman edited this page Jun 8, 2024 · 8 revisions

Overview

The frame-ancestors directive specifies valid parents that may embed a page using <frame>, <iframe>, <object>, or <embed>. Resources can use this directive to avoid many UI Redressing attacks by avoiding being embedded into potentially hostile contexts. Sites can use this to avoid click-jacking attacks, by ensuring that their content is not embedded into other sites.

Note

frame-ancestors allows you to specify what parent source may embed a page. This differs from frame-src, which allows you to specify where iframes in a page may be loaded from.

In order for this to be most effective across a large swath of newer and older browsers, use this together with the X-Frame-Options header.

X-Frame-Options frame-ancestors
DENY 'none'
SAMEORIGIN 'self'

Affects: <frame>; <iframe>; <object>; <embed>

Required reading:

Usage examples

Accepts one or more schemes or hosts, the 'self' keyword, or the 'none' keyword.

frame-ancestors 'none'
frame-ancestors 'self'
frame-ancestors example.com
frame-ancestors example.com example.org
frame-ancestors https://*.example.com
frame-ancestors https:

Fallbacks

frame-ancestors does not fallback to default-src.

Possible errors

[ERROR] directive frame-ancestors has an invalid value

Possible allowed values for frame-ancestors are:

  1. 'none'
  2. A scheme like https:
  3. A host like example.com
  4. A keyword like 'self'
  5. A nonce (although this is highly unusual)
  6. A sha256 hash (although this is highly unusual)

This error message means that the value does not match expected/correct patterns for any of these types.

For developers

ABNF (CSP3)

directive-name  = "frame-ancestors"
directive-value = serialized-source-list

See ABNF: serialized-source-list

Type

References

Clone this wiki locally