liveBook · Manning

X-frame-options

As explained in Building Web APIs with ASP.NET Core

An HTTP response header that controls whether a browser may render a page inside frames or iframes.

X-Frame-Options is an HTTP response header that helps protect a web API from clickjacking by controlling which sources may load its pages inside FRAME or IFRAME elements. section 12.1.4

Add the header in Program.cs with the other HTTP security headers. The shown configuration runs outside development and sets the value to sameorigin, allowing framing only from the same origin. section 12.1.4

Configure the response header

Inside the production branch, add middleware that appends context.Response.Headers.Add("X-Frame-Options", "sameorigin"). Keep it alongside HSTS, X-XSS-Protection, X-Content-Type-Options, Content-Security-Policy, and Referrer-Policy settings.

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines the security purpose and demonstrates a sameorigin middleware configuration, without detailing browser validation or testing.
Examples
Shows Program.cs middleware adding the X-Frame-Options response header with the value sameorigin.
What you can do after
Operate/configure the response header in Program.cs as part of production HTTP security middleware.
How it connects
Groups X-Frame-Options with HSTS, XSS protection, content-type options, content security policy, and referrer policy.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.