liveBook · Manning

Hsts header

As explained in ASP.NET Core in Action, 3e

HTTP Strict Transport Security is a web security policy that lets a site instruct browsers to use HTTPS for subsequent requests.

HTTP Strict Transport Security (HSTS) is a security policy that instructs browsers to use HTTPS for all subsequent requests to an application. After receiving a valid HSTS header over HTTPS, a browser upgrades http:// requests to https:// automatically. section 28.4 section 28.4.1

Use HSTS with these practical boundaries:

  • Send the header only in an HTTPS response; it affects browser requests, not server-to-server communication or mobile apps. section 28.4.1
  • Enable HSTS for production sites that always intend to use HTTPS, but generally leave it disabled during local development. section 28.4.1
  • Combine HSTS with HTTP-to-HTTPS redirection because HSTS takes effect only after the browser has made an initial HTTPS request. section 28.5
  • Treat enforcement as difficult to undo; use preload, subdomains, and long max-age values only when the entire site is ready for HTTPS. section 28.4.1

Configure HSTS in ASP.NET Core

Register HstsMiddleware settings and enable it only in production: builder.Services.AddHsts(options => { options.MaxAge = TimeSpan.FromHours(1); }); then use if (app.Environment.IsProduction()) { app.UseHsts(); }. The default max-age is 30 days; the example changes it to one hour.

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains browser behavior, deployment boundaries, middleware configuration, and preload options without detailing header parsing internals.
Examples
Uses ASP.NET Core HstsMiddleware with production gating, max-age configuration, preload, subdomains, and excluded hosts.
What it assumes
Assumes HTTPS is available and distinguishes browser clients from server-to-server and mobile clients.
What you can do after
Configure ASP.NET Core HstsMiddleware for production and choose appropriate max-age, preload, and subdomain settings.
How it connects
Connects HSTS with HTTPS, HTTP-to-HTTPS redirection, HTTP security headers, Content Security Policy, and HstsMiddleware.

Also explained in

Compare how 5 books explain hsts header →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.