By default ASP.NET MVC 5 adds the X-Frame-Options HTTP header to your response.
What does this header do?
From MDN:
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>
or<object>
. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.
What is clickjacking?
From OWASP:
Clickjacking, also known as a "UI redress attack", is when 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 the top level page. Thus, the attacker is "hijacking" clicks meant for their page and routing them to another page, most likely owned by another application, domain, or both.
Using a similar technique, keystrokes can also be hijacked. With a carefully crafted combination of stylesheets, iframes, and text boxes, a user can be led to believe they are typing in the password to their email or bank account, but are instead typing into an invisible frame controlled by the attacker.
How to disable this header?
As mentioned at the beginning of this article ASP.NET MVC 5 adds this header to your response by default and this for a very good reason. Despite this fact I had a situation were I wanted to disable it and remove this header from the response. Easiest way to do this is by adding the following line to the Application_Start()
method inside Global.asax
:
System.Web.Helpers.AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
Remark: This will make your website more vulnerable, so try to avoid it whenever possible.