liveBook · Manning

Hsts header

As explained in Grokking Web Application Security

HTTP Strict Transport Security is an HTTP security standard that instructs browsers to access a website only over HTTPS for a specified period.

How can a website stop browsers from falling back to insecure HTTP? An HTTP Strict Transport Security (HSTS) header tells browsers to use HTTPS for a specified period, helping prevent SSL-stripping and man-in-the-middle attacks. section 3.6 section 7.3

A one-week HSTS policy

Strict-Transport-Security: max-age=604800 tells a browser to remember the HTTPS-only rule for 604,800 seconds—one week. section 3.6

Use HSTS as part of a complete HTTPS configuration:

  • Deploy a valid digital certificate and serve the application over HTTPS. section 3.11
  • Redirect HTTP connections on port 80 to their HTTPS counterparts on port 443. section 7.3
  • Send the HSTS header from the secure server so browsers can upgrade future requests without waiting for a redirect. section 7.3
server {
  listen 80;
  server_name example.com;
  return 301 https://$server_name$request_uri;    #1
}

server {
  listen 443 ssl;
  server_name example.com;
  
  ssl_certificate /path/to/ssl/certificate.crt;   #2
  
  ssl_certificate_key /path/to/ssl/private.key;
  add_header Strict-Transport-Security
  
    "max-age=31536000";                           #3
  ssl_protocols TLSv1.3;                          #4
}

An NGINX configuration combines the HTTP-to-HTTPS redirect, certificate settings, HSTS, and TLS 1.3. section 7.3

How Grokking Web Application Security covers it

How deep it goes
Explains browser policy and max-age, then stops short of broader HSTS options while showing an integrated NGINX configuration.
Examples
Uses one-week and one-year max-age headers plus an NGINX server configuration with an HTTP redirect and TLS 1.3.
What it assumes
Assumes a deployed web application and teaches HTTPS certificates, redirects, and browser enforcement as the surrounding setup.
What you can do after
Configure HSTS alongside HTTPS certificates, HTTP redirects, and secure server settings.
How it connects
Connects HSTS with HTTPS, HTTP redirects, SSL stripping, man-in-the-middle attacks, digital certificates, and TLS.

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 Grokking Web Application Security. The section links point to the parts of the book it draws on.