❤️
SecurityHeaders.nl

X-Frame-Options

The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe>, <embed> or <object>.

Clickjacking Prevention

Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites. In a clickjacking attack, an attacker uses multiple transparent or opaque layers to trick a user into clicking on a button or link on another page when they were intending to click on the top level page.

Directives

There are two possible directives for X-Frame-Options:

X-Frame-Options: DENY

This is the most secure setting. The page cannot be displayed in a frame, regardless of the site attempting to do so. Even your own site cannot embed the page.

X-Frame-Options: SAMEORIGIN

The page can only be displayed in a frame on the same origin as the page itself. If your site is example.com, you can embed your own pages, but malicious-site.com cannot.

Modern Alternative: CSP frame-ancestors

While X-Frame-Options is still widely supported, the modern approach to preventing clickjacking is using the frame-ancestors directive in your Content-Security-Policy (CSP).

For example: Content-Security-Policy: frame-ancestors 'none'; achieves the same result as X-Frame-Options: DENY, but offers much more granular control. It is recommended to use both headers for maximum compatibility with older browsers.