Set HSTS at the server layer, not in client code. The browser enforces the policy from the response header, so web servers, CDNs, or SSR platforms should send Strict-Transport-Security over HTTPS. This prevents a first visit over HTTP from exposing cookies in plaintext and makes future requests use HTTPS automatically, including when users type the HTTP version of a URL.
Why HSTS Has to Be a Server-Sent Policy
HSTS only works when the browser receives Strict-Transport-Security from an HTTPS response and stores it as an enforcement rule for that origin. That means the control belongs in the delivery layer, such as the web server, CDN, or SSR platform, not in React components or client-side JavaScript. A client-rendered app can reference the policy, but it cannot establish it.
The practical security value is not just “redirect HTTP to HTTPS.” HSTS removes the browser’s willingness to fall back to HTTP for the same site once the policy is cached. That closes a common downgrade path where the first request, or a manually typed HTTP URL, could otherwise expose session cookies before the browser learns to insist on TLS.
For React teams, this is why framework-level frontend work is not enough. Even a perfectly secure SPA can still be vulnerable if the origin ever serves the site over plain HTTP or if the initial response does not set HSTS. The protection depends on the response path that the browser actually trusts, not on the application bundle.
How to Protect Session Cookies in Practice
To make HSTS actually protect session cookies, the site must be HTTPS-only at the origin, issue the HSTS header on every secure response, and ensure cookies are marked to prevent unintended exposure. HSTS reduces the chance that cookies travel over HTTP, but cookie attributes still matter because they define when the browser will attach a cookie and whether JavaScript can read it.
Use Secure for any session cookie so the browser will not send it over HTTP. Combine that with HttpOnly so client-side code cannot read the cookie if script execution is compromised. If the application is cross-site aware, set SameSite deliberately rather than accepting defaults by accident. HSTS and cookie flags solve different parts of the problem, and neither substitutes for the other.
For teams using CDNs or edge platforms, verify that the header is emitted at the edge and not stripped or overridden by downstream routing. For SSR platforms, confirm the header is present on the HTML response that first lands in the browser. If you rely on a redirect from HTTP to HTTPS, remember that redirect alone does not protect the very first plaintext request unless the browser already has an HSTS policy cached.
OWASP’s Application Security Verification Standard and the OWASP Cheat Sheet Series are useful references for aligning header handling and session controls with broader web application hardening.
Deployment Checks That Usually Decide Whether It Works
The most common failure is assuming the React app can “set” HSTS. It cannot. Another common failure is adding the header only on a subset of routes, only in production, or only after login. HSTS should be present on the initial HTTPS response for the origin, because that is the response that teaches the browser to stop using HTTP later.
Teams should also validate that the header value is sensible for their rollout stage. A short max-age may be appropriate during testing, but production protection depends on a long-lived policy. If you intend to include subdomains, do so only when every relevant subdomain is HTTPS-ready, because HSTS can break legacy HTTP endpoints that are still in use.
For operational assurance, test from a clean browser profile, an incognito session, or a fresh device so you are seeing first-contact behaviour rather than a previously cached policy. That is the only way to confirm the site is actually eliminating the plaintext bootstrap path that HSTS is meant to close.
For implementation and verification, the OWASP Web Security Testing Guide is a practical companion, and NIST Cybersecurity Framework 2.0 helps place transport protection and secure service delivery into a broader control program.
Risk and Threat Considerations
HSTS mainly addresses downgrade and first-visit exposure risk. If the policy is missing, delayed, or only partially deployed, an attacker who can influence network conditions or initial navigation may still benefit from plaintext bootstrap traffic, especially when session cookies or authentication redirects are involved.
Failure mechanism: The browser does not enforce HTTPS until it has received and cached HSTS over a secure response, so the first request or an unprotected route can still be reached over HTTP before enforcement begins.
Impact: Session cookies, login flows, or redirect targets can be exposed in transit, and the user experience may silently fall back to weaker transport until the browser learns the policy.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Agentic AI Top 10 address the attack and risk surface, while CIS Controls v8 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| CIS Controls v8 | CIS 6 — Access Control Management | Session-cookie protection depends on controlling exposure and access paths. |
| Recommendation — Enforce least-privilege access and restrict session handling to HTTPS-only paths. | ||
| NIST CSF 2.0 | PR.DS — Data Security | HSTS protects session data in transit by preventing plaintext exposure. |
| PR.AC — Identity Management, Authentication and Access Control | Session cookies are access-bearing material that must be protected from downgrade exposure. | |
| PR.PT — Protective Technology | HSTS is a protective transport control enforced by the browser. | |
| Recommendation — Protect data in transit with HTTPS-only delivery and secure cookie handling. Apply access-control protections to session cookies and login flows. Deploy transport protections at the server or edge so browsers enforce HTTPS. | ||
| OWASP Agentic AI Top 10 | A1 — Agent Identity and Access Control | Not selected |
Practitioner Guidance
What to verify: Confirm the HSTS header is present on the first HTTPS response from the real production origin and edge, not just in local development or behind a reverse proxy that behaves differently. Then verify session cookies also carry Secure and HttpOnly, because HSTS alone does not stop JavaScript access to a cookie already present in the browser.
Decision rule: If you cannot guarantee HTTPS on every subdomain you plan to include, keep HSTS scoped narrowly until those dependencies are remediated. If the site still serves any meaningful HTTP endpoint, treat HSTS as incomplete rather than symbolic.
Practitioner takeaway: The control is effective only when transport policy, cookie flags, and deployment path all agree, because one weak link in the first-contact flow can still expose the session.
Related resources from NHI Mgmt Group
- How should security teams implement vendor risk management in a way that actually scales?
- How should security teams implement employee risk scoring in a way that actually changes behaviour?
- How should security teams implement 3-legged OAuth for application access in a way that reduces abuse risk?
- How should security teams implement authentication in React Router apps with server-side rendering?
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on September 17, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org