• HTTP
  • HTTP
  • A typical HTTP session
  • HTTP caching
  • HTTP conditional requests
  • Protocol upgrade mechanism
  • HTTP Observatory
  • Permissions Policy Experimental
  • CORS errors
    1. Reason: CORS header 'Origin' cannot be added
    2. Reason: CORS request not HTTP
    3. Reason: invalid token 'xyz' in CORS header 'Access-Control-Allow-Headers'
    4. Reference
    5. Accept-Encoding
    6. Accept-Ranges
    7. Access-Control-Allow-Origin
    8. Access-Control-Request-Method
    9. Alt-Used
    10. Attribution-Reporting-Eligible Experimental
    11. Attribution-Reporting-Register-Source Experimental
    12. Attribution-Reporting-Register-Trigger Experimental
    13. Connection
    14. Content-DPR Non-standard Deprecated
    15. Content-Location
    16. Content-Type
    17. Critical-CH Experimental
    18. Date
    19. DNT Non-standard Deprecated
    20. Downlink Experimental
    21. DPR Non-standard Deprecated
    22. Early-Data Experimental
    23. ECT Experimental
    24. Expect-CT Deprecated
    25. Host
    26. If-Range
    27. Link
    28. NEL Experimental
    29. No-Vary-Search Experimental
    30. Observe-Browsing-Topics Experimental Non-standard
    31. Origin-Agent-Cluster Experimental
    32. Permissions-Policy Experimental
    33. Pragma Deprecated
    34. Range
    35. Report-To Non-standard Deprecated
    36. Reporting-Endpoints Experimental
    37. RTT Experimental
    38. Save-Data Experimental
    39. Sec-Browsing-Topics Experimental Non-standard
    40. Sec-CH-Prefers-Color-Scheme Experimental
    41. Sec-CH-Prefers-Reduced-Motion Experimental
    42. Sec-CH-Prefers-Reduced-Transparency Experimental
    43. Sec-CH-UA Experimental
    44. Sec-CH-UA-Arch Experimental
    45. Sec-CH-UA-Bitness Experimental
    46. Sec-CH-UA-Form-Factors Experimental
    47. Sec-CH-UA-Full-Version Deprecated
    48. Sec-CH-UA-Full-Version-List Experimental
    49. Sec-CH-UA-Mobile Experimental
    50. Sec-CH-UA-Model Experimental
    51. Sec-CH-UA-Platform Experimental
    52. Sec-CH-UA-Platform-Version Experimental
    53. Sec-CH-UA-WoW64 Experimental
    54. Sec-Fetch-User
    55. Sec-GPC Experimental
    56. Sec-WebSocket-Key
    57. Server-Timing
    58. Set-Cookie
    59. Set-Login Experimental
    60. Speculation-Rules Experimental
    61. Supports-Loading-Mode Experimental
    62. Tk Non-standard Deprecated
    63. Upgrade-Insecure-Requests
    64. Viewport-Width Non-standard Deprecated
    65. Warning Deprecated
    66. Width Non-standard Deprecated
    67. X-DNS-Prefetch-Control Non-standard
    68. X-Forwarded-For Non-standard
    69. X-Forwarded-Host Non-standard
    70. X-Forwarded-Proto Non-standard
    71. X-Permitted-Cross-Domain-Policies Non-standard
    72. X-Powered-By Non-standard
    73. X-Robots-Tag Non-standard
    74. X-XSS-Protection Non-standard Deprecated
  • GET
  • POST
  • 100 Continue
  • 200 OK
  • 204 No Content
  • 208 Already Reported
  • 302 Found
  • 308 Permanent Redirect
  • 403 Forbidden
  • 407 Proxy Authentication Required
  • 411 Length Required
  • 415 Unsupported Media Type
  • 421 Misdirected Request
  • 425 Too Early
  • 431 Request Header Fields Too Large
  • 502 Bad Gateway
  • 506 Variant Also Negotiates
  • 511 Network Authentication Required
  • CSP: block-all-mixed-content Deprecated
  • CSP: fenced-frame-src Experimental
  • CSP: frame-src
  • CSP: object-src
  • CSP: prefetch-src Non-standard Deprecated
  • CSP: report-uri Deprecated
  • CSP: require-trusted-types-for Experimental
  • CSP: script-src-elem
  • CSP: trusted-types Experimental
  • Permissions-Policy directives Experimental
    1. Permissions-Policy: accelerometer Experimental
    2. Permissions-Policy: ambient-light-sensor Experimental
    3. Permissions-Policy: attribution-reporting Experimental
    4. Permissions-Policy: autoplay Experimental
    5. Permissions-Policy: bluetooth Experimental
    6. Permissions-Policy: browsing-topics Experimental Non-standard
    7. Permissions-Policy: camera Experimental
    8. Permissions-Policy: compute-pressure Experimental
    9. Permissions-Policy: cross-origin-isolated Experimental
    10. Permissions-Policy: display-capture Experimental
    11. Permissions-Policy: document-domain Experimental
    12. Permissions-Policy: encrypted-media Experimental
    13. Permissions-Policy: fullscreen Experimental
    14. Permissions-Policy: gamepad Experimental
    15. Permissions-Policy: geolocation Experimental
    16. Permissions-Policy: gyroscope Experimental
    17. Permissions-Policy: hid Experimental
    18. Permissions-Policy: identity-credentials-get Experimental
    19. Permissions-Policy: idle-detection Experimental
    20. Permissions-Policy: local-fonts Experimental
    21. Permissions-Policy: magnetometer Experimental
    22. Permissions-Policy: microphone Experimental
    23. Permissions-Policy: midi Experimental
    24. Permissions-Policy: otp-credentials Experimental
    25. Permissions-Policy: payment Experimental
    26. Permissions-Policy: picture-in-picture Experimental
    27. Permissions-Policy: publickey-credentials-create Experimental
    28. Permissions-Policy: publickey-credentials-get Experimental
    29. Permissions-Policy: screen-wake-lock Experimental
    30. Permissions-Policy: serial Experimental
    31. Permissions-Policy: speaker-selection Experimental
    32. Permissions-Policy: storage-access Experimental
    33. Permissions-Policy: usb Experimental
    34. Permissions-Policy: web-share Experimental
    35. Permissions-Policy: window-management Experimental
    36. Permissions-Policy: xr-spatial-tracking Experimental
  • HSTS) informs browsers that the site should only be accessed using HTTPS, and that any future attempts to access it using HTTP should automatically be upgraded to HTTPS.

    Note: This is more secure than configuring a HTTP to HTTPS (301) redirect on your server, as the initial HTTP connection is still vulnerable to a man-in-the-middle attack.

    Header type Response header
    Forbidden request header No
  • Syntax

    http
    Strict-Transport-Security: max-age=<expire-time>
    Strict-Transport-Security: max-age=<expire-time>; includeSubDomains
    Strict-Transport-Security: max-age=<expire-time>; includeSubDomains; preload
    

    Directives

    max-age=<expire-time>

    The time, in seconds, that the browser should remember that a site is only to be accessed using HTTPS.

    includeSubDomains Optional

    If this optional parameter is specified, this rule applies to all of the site's subdomains as well.

    preload Optional Non-standard

    See Preloading Strict Transport Security for details. When using preload, the max-age directive must be at least 31536000 (1 year), and the includeSubDomains directive must be present. Not part of the specification.

    Description

    If a website accepts a connection through HTTP and redirects to HTTPS, visitors may initially communicate with the non-encrypted version of the site before being redirected, if, for example, the visitor types http://www.foo.com/ or even just foo.com. This creates an opportunity for a man-in-the-middle attack. The redirect could be exploited to direct visitors to a malicious site instead of the secure version of the original site.

    The Strict-Transport-Security header informs the browser that it should never load a site using HTTP and should automatically convert all attempts to access the site using HTTP to HTTPS requests instead.

    Note: The Strict-Transport-Security header is ignored by the browser when your site has only been accessed using HTTP. Once your site is accessed over HTTPS with no certificate errors, the browser knows your site is HTTPS-capable and will honor the Strict-Transport-Security header. Browsers do this as attackers may intercept HTTP connections to the site and inject or remove the header.

    Strict Transport Security example scenario

    Assume you have logged into a free Wi-Fi access point at an airport and start surfing the web, visiting your online banking service to check your balance and pay a couple of bills. Unfortunately, the access point you're using is actually a hacker's laptop, and they're intercepting your original HTTP request and redirecting you to a clone of your bank's site instead of the real thing. Now your private data is exposed to the hacker.

    Strict Transport Security resolves this problem; as long as you've accessed your bank's website once using HTTPS, and the bank's website uses Strict Transport Security, your browser will know to automatically use only HTTPS, which prevents hackers from performing this sort of man-in-the-middle attack.

    How the browser handles Strict Transport Security

    The first time a site is accessed using HTTPS and it returns the Strict-Transport-Security header, the browser records this information, so that future attempts to load the site using HTTP will automatically use HTTPS instead.

    When the expiration time specified by the Strict-Transport-Security header elapses, the next attempt to load the site via HTTP will proceed as normal instead of automatically using HTTPS.

    Whenever the Strict-Transport-Security header is delivered to the browser, it will update the expiration time for that site, so sites can refresh this information and prevent the timeout from expiring. Should it be necessary to disable Strict Transport Security, setting the max-age to 0 (over an HTTPS connection) will immediately expire the Strict-Transport-Security header, allowing access via HTTP.

    Preloading Strict Transport Security

    Google maintains an HSTS preload service. By following the guidelines and successfully submitting your domain, you can ensure that browsers will connect to your domain only via secure connections. While the service is hosted by Google, all browsers are using this preload list. However, it is not part of the HSTS specification and should not be treated as official.

    Examples

    Using Strict-Transport-Security

    All present and future subdomains will be HTTPS for a max-age of 1 year. This blocks access to pages or subdomains that can only be served over HTTP.

    http
    Strict-Transport-Security: max-age=31536000; includeSubDomains
    

    Although a max-age of 1 year is acceptable for a domain, two years is the recommended value as explained on https://hstspreload.org.

    In the following example, max-age is set to 2 years, and is suffixed with preload, which is necessary for inclusion in all major web browsers' HSTS preload lists, like Chromium, Edge, and Firefox.

    http
    Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
    

    Specifications

    Specification
    HTTP Strict Transport Security (HSTS)
    # section-6.1

    Browser compatibility

    BCD tables only load in the browser

    See also