Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated
X-Frame-Options is a setting that stops your page from being shown inside another site's frame. The server tells the browser, in a response header, whether this page may be displayed inside a frame. RFC 7034 describes it as a way to improve the defense against clickjacking.
How does X-Frame-Options work?
A museum would not want its paintings displayed in someone else's frame. Clickjacking lays another page under an invisible frame, so that a visitor's click lands on a button they did not mean to press.
There are mainly two values. DENY does not allow display inside any frame. SAMEORIGIN allows display only inside a frame created by a page of the same origin.
RFC 7034 also describes ALLOW-FROM, which allows only a named origin. The RFC itself says, however, that this began as an extension in some browsers and has not been consistently adopted by others.
The OWASP Clickjacking Defense Cheat Sheet calls ALLOW-FROM obsolete and warns that it does not work in modern browsers. In a browser that does not support it, the defense disappears.
The successor is the CSP frame-ancestors directive. The same OWASP document cites the CSP specification as saying that when this directive is present, X-Frame-Options should be ignored.
The flow of harm is summarized in the clickjacking page. Whether the header is present from outside can be examined in the free URL check.
Why does X-Frame-Options matter?
If a payment or settings page can be placed inside another site's frame, it can become the stage for a trick that misleads where a person clicks. The advantage is that adding a single header lets the browser refuse the display.
One caution is a design where you use your own pages in frames. If you have an embedded form or an admin preview, DENY also blocks display inside your own site. In that case, use SAMEORIGIN, or name the allowed parties with frame-ancestors. When you configure something new, you can build around frame-ancestors and add X-Frame-Options alongside it as a precaution for older browsers.
Related terms
- Clickjacking: a trick that lays an invisible frame to make a person act unintentionally
- CSP: a setting that tells the browser which sources it may load from
- HTTP security headers: extra information in a response that tells the browser how to behave safely
- Same-origin policy: a browser rule that stops one site from reading data from another
Frequently asked questions
Should I choose DENY or SAMEORIGIN?
If you never place your pages inside frames of your own other pages, DENY is the easier choice to understand. If your own pages do embed each other, choose SAMEORIGIN. Check whether any embedding exists before you decide.
Can I use ALLOW-FROM?
Avoid it. RFC 7034 says it has not been consistently adopted by other browsers, and OWASP warns that it does not work in modern browsers. To name an allowed party, use the CSP frame-ancestors directive.
Next step
The page on clickjacking describes how framing is abused. To talk through your header configuration, contact us.
Frequently asked questions
Should I choose DENY or SAMEORIGIN?
If you never place your pages inside frames of your own other pages, DENY is the easier choice to understand. If your own pages do embed each other, choose SAMEORIGIN. Check whether any embedding exists before you decide.
Can I use ALLOW-FROM?
Avoid it. RFC 7034 says it has not been consistently adopted by other browsers, and OWASP warns that it does not work in modern browsers. To name an allowed party, use the CSP frame-ancestors directive.