| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Strict-Transport-Security | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The HTTP Strict-Transport-Security response header (often abbreviated as HSTS) informs browsers that the host should only be accessed using HTTPS, and that any future attempts to access it using HTTP should automatically be upgraded to HTTPS.
Additionally, on future connections to the host, the browser will not allow the user to bypass secure connection errors, such as an invalid certificate.
HSTS identifies a host by its domain name only.
| Header type | Response header |
|---|
Strict-Transport-Security: max-age=<expire-time>
Strict-Transport-Security: max-age=<expire-time>; includeSubDomains
Strict-Transport-Security: max-age=<expire-time>; includeSubDomains; preload
max-age=<expire-time>The time, in seconds, that the browser should remember that a host is only to be accessed using HTTPS.
includeSubDomains OptionalIf this directive is specified, the HSTS policy applies to all subdomains of the host's domain as well.
preload Optional 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.
The Strict-Transport-Security header informs the browser that all connections to the host must use HTTPS.
Although it is a response header, it does not affect how the browser handles the current response, but rather
how it makes future requests.
When an HTTPS response includes the Strict-Transport-Security header, the browser adds the host's domain name
to its persistent list of HSTS hosts.
If the domain name is already in the list, the expiration time and includeSubDomains directive are updated.
The host is identified only by its domain name. An IP address cannot be an HSTS host.
HSTS applies to all ports of the host, regardless of what port was used for the request.
Before loading an http URL, the browser checks the domain name against its HSTS hosts list.
If the domain name is a case-insensitive match for an HSTS host or is a subdomain of one that specified includeSubDomains,
then the browser replaces the URL scheme with https.
If the URL specifies port 80, the browser changes it to 443.
Any other explicit port number remains unchanged, and the browser connects to that port using HTTPS.
If a TLS warning or error, such as an invalid certificate, occurs when connecting to an HSTS host, the browser does not offer the user a way to proceed or "click through" the error message, which would compromise the intention of strict security.
Note:
The host must send the Strict-Transport-Security header over HTTPS only, not insecure HTTP.
Browsers ignore the header if sent over HTTP to prevent a manipulator in the middle (MITM)
from altering the header to expire prematurely or adding it for a host that doesn't support HTTPS.
Every time the browser receives a Strict-Transport-Security header, it updates the host's HSTS expiration time by
adding max-age to the current time.
Using a fixed value for max-age can prevent HSTS from expiring, as each subsequent response will push the expiration farther into the future.
If the Strict-Transport-Security header is missing in a response from a host that previously sent one, the previous header remains in effect until its expiration time.
To disable HSTS, set max-age=0.
This only takes effect once the browser makes a secure request and receives the response header.
By design, you cannot disable HSTS over insecure HTTP.
The includeSubDomains directive instructs the browser to apply a domain's HSTS policy to its subdomains as well.
An HSTS policy for secure.example.com with includeSubDomains also applies to login.secure.example.com
and admin.login.secure.example.com. But it does not apply to example.com or insecure.example.com.
Each subdomain host should include Strict-Transport-Security headers in its responses even if the
superdomain uses includeSubDomains, because a browser may contact a subdomain host before the superdomain.
For example, if example.com includes the HSTS header with includeSubDomains, but all existing links
go directly to www.example.com, the browser will never see example.com's HSTS header.
Therefore, www.example.com also should send HSTS headers.
The browser stores the HSTS policy for each domain and subdomain independently, regardless of the includeSubDomains directive.
If both example.com and login.example.com send HSTS headers, the browser stores two separate HSTS policies,
and they can expire independently. If example.com used includeSubDomains, then login.example.com remains covered
if either one of the policies expires.
If max-age=0, includeSubDomains has no effect, since the domain that specified includeSubDomains is
immediately deleted from the HSTS hosts list; this does not delete separate HSTS policies of each subdomain.
If the host accepts insecure HTTP requests, it should respond with a permanent redirect (such as status code 301)
having an https URL in the Location header.
The redirect must not include the Strict-Transport-Security header since the request used insecure HTTP
but the header must be sent via HTTPS only.
After the browser follows the redirect and makes a new request using HTTPS, the response
should include the Strict-Transport-Security header to ensure that future attempts to load an http URL
will use HTTPS immediately, without requiring a redirect.
One weakness of HSTS is that it does not take effect until the browser has made at least one secure connection to the host
and received the Strict-Transport-Security header.
If the browser loads an insecure http URL prior to knowing that the host is an HSTS host, the initial request is
vulnerable to network attacks.
Preloading mitigates this problem.
At home, the user visits http://example.com/ for the first time.
Since the URL scheme is http and the browser does not have it in its HSTS hosts list, the connection uses insecure HTTP.
The server responds with a 301 Moved Permanently redirect to https://example.com/.
The browser makes a new request, this time using HTTPS.
The response, made via HTTPS, includes the header:
Strict-Transport-Security: max-age=31536000; includeSubDomains
The browser remembers example.com as an HSTS host, and that it specified includeSubDomains.
A few weeks later, the user is at the airport and decides to use the free Wi-Fi. But unknowingly, they connect to a rogue access point running on an attacker's laptop.
The user opens http://login.example.com/. Because the browser remembers example.com as an HSTS host and the includeSubDomains directive was used, the browser uses HTTPS.
The attacker intercepts the request with a fake HTTPS server, but does not have a valid certificate for the domain.
The browser displays an invalid certificate error, and does not allow the user to bypass it, thus preventing them from giving their password to the attacker.
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.
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.
Strict-Transport-Security: max-age=31536000; includeSubDomains
A max-age of 1 year is the minimum value accepted for HSTS preloading. The following example uses 2 years, which is the value shown in the example header 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.
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
| Specification |
|---|
| HTTP Strict Transport Security (HSTS) # section-6.1 |
This page was last modified on Sep 11, 2026 by MDN contributors.
Reason: CORS disabledReason: CORS header 'Access-Control-Allow-Origin' does not match 'xyz'Reason: CORS header 'Access-Control-Allow-Origin' missingReason: CORS header 'Origin' cannot be addedReason: CORS preflight channel did not succeedReason: CORS request did not succeedReason: CORS request external redirect not allowedReason: CORS request not HTTPReason: Credential is not supported if the CORS header 'Access-Control-Allow-Origin' is '*'Reason: Did not find method in CORS header 'Access-Control-Allow-Methods'Reason: expected 'true' in CORS header 'Access-Control-Allow-Credentials'Reason: invalid token 'xyz' in CORS header 'Access-Control-Allow-Headers'Reason: invalid token 'xyz' in CORS header 'Access-Control-Allow-Methods'Reason: missing token 'xyz' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channelReason: Multiple CORS header 'Access-Control-Allow-Origin' not allowedAcceptAccept-CHAccept-EncodingAccept-LanguageAccept-PatchAccept-PostAccept-QueryAccept-RangesAccess-Control-Allow-CredentialsAccess-Control-Allow-HeadersAccess-Control-Allow-MethodsAccess-Control-Allow-OriginAccess-Control-Expose-HeadersAccess-Control-Max-AgeAccess-Control-Request-HeadersAccess-Control-Request-MethodActivate-Storage-AccessAgeAllowAlt-SvcAlt-UsedAttribution-Reporting-EligibleAttribution-Reporting-Register-SourceAttribution-Reporting-Register-TriggerAuthorizationAvailable-DictionaryCache-ControlClear-Site-DataConnectionContent-DigestContent-DispositionContent-DPRContent-EncodingContent-LanguageContent-LengthContent-LocationContent-RangeContent-Security-PolicyContent-Security-Policy-Report-OnlyContent-TypeCookieCritical-CHCross-Origin-Embedder-PolicyCross-Origin-Embedder-Policy-Report-OnlyCross-Origin-Opener-PolicyCross-Origin-Resource-PolicyDateDevice-MemoryDictionary-IDDNTDownlinkDPREarly-DataECTETagExpectExpect-CTExpiresForwardedFromHostIdempotency-KeyIf-MatchIf-Modified-SinceIf-None-MatchIf-RangeIf-Unmodified-SinceIntegrity-PolicyIntegrity-Policy-Report-OnlyKeep-AliveLast-ModifiedLinkLocationMax-ForwardsNELNo-Vary-SearchObserve-Browsing-TopicsOriginOrigin-Agent-ClusterPermissions-PolicyPermissions-Policy-Report-OnlyPragmaPreferPreference-AppliedPriorityProxy-AuthenticateProxy-AuthorizationRangeRefererReferrer-PolicyRefreshReport-ToReporting-EndpointsRepr-DigestRetry-AfterRTTSave-DataSec-Browsing-TopicsSec-CH-Device-MemorySec-CH-DPRSec-CH-Prefers-Color-SchemeSec-CH-Prefers-Reduced-MotionSec-CH-Prefers-Reduced-TransparencySec-CH-UASec-CH-UA-ArchSec-CH-UA-BitnessSec-CH-UA-Form-FactorsSec-CH-UA-Full-VersionSec-CH-UA-Full-Version-ListSec-CH-UA-MobileSec-CH-UA-ModelSec-CH-UA-PlatformSec-CH-UA-Platform-VersionSec-CH-UA-WoW64Sec-CH-Viewport-HeightSec-CH-Viewport-WidthSec-CH-WidthSec-Fetch-DestSec-Fetch-ModeSec-Fetch-SiteSec-Fetch-Storage-AccessSec-Fetch-UserSec-GPCSec-Private-State-TokenSec-Private-State-Token-Crypto-VersionSec-Private-State-Token-LifetimeSec-PurposeSec-Redemption-RecordSec-Speculation-TagsSec-WebSocket-AcceptSec-WebSocket-ExtensionsSec-WebSocket-KeySec-WebSocket-ProtocolSec-WebSocket-VersionServerServer-TimingService-WorkerService-Worker-AllowedService-Worker-Navigation-PreloadSet-CookieSet-LoginSourceMapSpeculation-RulesStrict-Transport-SecuritySupports-Loading-ModeTETiming-Allow-OriginTkTrailerTransfer-EncodingUpgradeUpgrade-Insecure-RequestsUse-As-DictionaryUser-AgentVaryViaViewport-WidthWant-Content-DigestWant-Repr-DigestWarningWidthWWW-AuthenticateX-Content-Type-OptionsX-DNS-Prefetch-ControlX-Forwarded-ForX-Forwarded-HostX-Forwarded-ProtoX-Frame-OptionsX-Permitted-Cross-Domain-PoliciesX-Powered-ByX-Robots-TagX-XSS-Protection100 Continue101 Switching Protocols103 Early Hints200 OK201 Created202 Accepted203 Non-Authoritative Information204 No Content205 Reset Content206 Partial Content207 Multi-Status208 Already Reported226 IM Used300 Multiple Choices301 Moved Permanently302 Found303 See Other304 Not Modified307 Temporary Redirect308 Permanent Redirect400 Bad Request401 Unauthorized402 Payment Required403 Forbidden404 Not Found405 Method Not Allowed406 Not Acceptable407 Proxy Authentication Required408 Request Timeout409 Conflict410 Gone411 Length Required412 Precondition Failed413 Content Too Large414 URI Too Long415 Unsupported Media Type416 Range Not Satisfiable417 Expectation Failed418 I'm a teapot421 Misdirected Request422 Unprocessable Content423 Locked424 Failed Dependency425 Too Early426 Upgrade Required428 Precondition Required429 Too Many Requests431 Request Header Fields Too Large451 Unavailable For Legal Reasons500 Internal Server Error501 Not Implemented502 Bad Gateway503 Service Unavailable504 Gateway Timeout505 HTTP Version Not Supported506 Variant Also Negotiates507 Insufficient Storage508 Loop Detected510 Not Extended511 Network Authentication Requiredbase-uriblock-all-mixed-contentchild-srcconnect-srcdefault-srcfenced-frame-srcfont-srcform-actionframe-ancestorsframe-srcimg-srcmanifest-srcmedia-srcobject-srcprefetch-srcreport-toreport-urirequire-trusted-types-forsandboxscript-srcscript-src-attrscript-src-elemstyle-srcstyle-src-attrstyle-src-elemtrusted-typesupgrade-insecure-requestsworker-srcaccelerometerambient-light-sensoraria-notifyattribution-reportingautoplaybluetoothbrowsing-topicscameracaptured-surface-controlch-ua-high-entropy-valuescompute-pressurecross-origin-isolateddeferred-fetchdeferred-fetch-minimaldisplay-captureencrypted-mediafullscreengamepadgeolocationgyroscopehididentity-credentials-getidle-detectionlanguage-detectorlanguage-modellocal-fontslocal-networklocal-network-accessloopback-networkmagnetometermicrophonemidion-device-speech-recognitionotp-credentialspaymentpicture-in-pictureprivate-state-token-issuanceprivate-state-token-redemptionpublickey-credentials-createpublickey-credentials-getscreen-wake-lockserialspeaker-selectionstorage-accesssummarizertranslatorunloadusbweb-sharewindow-managementxr-spatial-trackingYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |