frame-ancestors CSP Directive (frame-ancestors)
Why frame-ancestors Matters
frame-ancestors is the modern, more flexible replacement for X-Frame-Options. While X-Frame-Options only supports DENY, SAMEORIGIN, and the deprecated ALLOW-FROM, frame-ancestors can specify multiple allowed origins with full URL pattern matching.
This directive is critical for preventing clickjacking attacks, where an attacker embeds your site in a transparent iframe and tricks users into clicking buttons on your site while thinking they are interacting with the visible page. Banks, social media sites, and any page with sensitive actions should use frame-ancestors 'none' or 'self'.
Unlike most CSP directives, frame-ancestors in an enforcing CSP takes precedence over X-Frame-Options. However, for backward compatibility with browsers that do not support CSP (mainly IE11), setting both frame-ancestors and X-Frame-Options is recommended.
Checking Your Setup
A security audit checks both the frame-ancestors CSP directive and the X-Frame-Options header. Verify your site cannot be framed by untrusted origins. If you need to allow specific partners to embed your content, list their origins explicitly in frame-ancestors.