X-Frame-Options
The HTTP X-Frame-Options response header is used to place restrictions on how the client’s browser can display the page rendering.
Usage
The HTTP X-Frame-Options response header is sent by a server to indicate whether the client is allowed to display a rendered page using HTML tags , , , or . This is an additional layer of security that a website can employ to protect against certain types of attacks. For example, clickjacking attacks, which lead users to click on something other than what they expect, are prevented using this HTTP header.
Note
The "X-" naming convention for HTTP headers, "X" referring to "experimental", has been deprecated and need to be transitioned to formal naming convention for HTTP headers.
This HTTP request header has directives deny, sameorigin, and allow-from.
deny
The deny directive instructs the browser not to display the page in a frame under any circumstances.
X-Frame-Options: deny
sameorigin
The sameorigin directive is less strict than deny. Using sameorigin implies that the client can display the page in a frame as long as the content is from the same site as the one that is serving the page.
X-Frame-Options: sameorigin
Note
The use of sameorigin is not restricted to the top level, parent, or the entire chain. However, unless all of the ancestors are of the same origin, the usefulness of this directive is in question.
allow-from URI
The allow-from directive is now obsolete and no longer be used. It once allowed browsers to display the content in a frame only for the specified URI.
X-Frame-Options: allow-from https://example.re/
In place of allow-from, the HTTP Content-Security-Policy header can be used with the frame-ancestors directive.
Takeaway
The HTTP X-Frame-Options header is used to provide additional security by directing clients whether they are allowed to display content inside of a frame.