Because a JWT is a bearer credential, whoever holds it can often use it. If the browser stores that token in a place that JavaScript, injected code, or browser tooling can read, the session becomes reusable outside the intended user context. That changes authentication from a controlled session into an extractable secret.
Why JWT Storage Choices Change the Threat Model
A JWT is not just an authentication artifact, it is often a reusable bearer secret. If it is stored where script, extensions, debugging tools, or injected code can reach it, the token can be replayed outside the intended session boundary. That is why storage is a security decision, not a convenience choice. The risk is not theoretical: NHI research from NHI Management Group shows secrets exposure remains widespread, with long-lived credentials and weak handling creating durable compromise paths in practice. See the Ultimate Guide to NHIs and the 52 NHI Breaches Analysis for the broader identity failure pattern.
Security teams often focus on token signing and expiry while underestimating the storage layer. A token protected by strong cryptography can still become the easiest path to account takeover if it sits in localStorage, a browser cache, or a loggable client state object. Current guidance also aligns with the control intent in NIST SP 800-53 Rev. 5 Security and Privacy Controls, which emphasizes limiting exposure of authenticators and protecting session material. In practice, many security teams discover token abuse only after a browser-side compromise or stolen endpoint session has already made the JWT reusable.
How Secure Storage Works in Practice
The safest storage pattern depends on where the token is used and what the application must defend against. For browser-based apps, many teams prefer an HTTP-only, Secure, SameSite cookie when the architecture supports it, because JavaScript cannot directly read it. That does not eliminate risk, but it reduces exposure to XSS and script-based token theft. For native apps or backend services, the stronger pattern is to keep JWTs out of client-readable storage entirely and bind them to the workload or session context where possible.
Operationally, the key is to separate identity proof from convenient state storage. That means:
- Prefer short-lived access tokens over long-lived reusable credentials.
- Avoid localStorage for sensitive bearer tokens when script access is in scope.
- Use HTTPS everywhere and mark cookies as HttpOnly, Secure, and appropriately scoped.
- Pair access tokens with refresh token controls, rotation, and revocation.
- Log token use patterns carefully without exposing raw token values in telemetry.
This becomes especially important when identity material is shared across browser apps, APIs, and automation. NHI Management Group’s Top 10 NHI Issues and Ultimate Guide to NHIs - What are Non-Human Identities show the same core lesson: once a credential becomes easy to extract, it becomes easy to replay. These controls tend to break down in single-page applications with weak XSS defenses, because any script execution path can turn storage into theft.
Where the Tradeoffs and Edge Cases Matter
Tighter token storage often increases implementation complexity, requiring organisations to balance usability, cross-site behavior, and session resilience against stronger theft resistance. That tradeoff is real, especially for SPAs, federated login flows, and mobile applications. There is no universal standard for this yet, but current guidance suggests minimizing client-readable bearer material wherever possible and shortening the lifetime of anything that must remain accessible.
Some edge cases deserve special care. A cookie-based approach can still be abused through CSRF if request defenses are weak. A client-side token can sometimes be acceptable for low-risk public data access, but only if the blast radius is small and revocation is fast. A backend-for-frontend pattern can reduce browser exposure, but it adds infrastructure and session management overhead. In environments with shared machines, hostile browser extensions, or aggressive content injection, even short-lived tokens can be compromised if the endpoint itself is not trusted. For identity programs that already struggle with secrets sprawl, the lesson from Code Formatting Tools Credential Leaks is clear: storage decisions fail fastest where developers assume the client is a safe place to keep secrets.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 and OWASP Agentic AI Top 10 address the attack and risk surface, while NIST CSF 2.0, NIST SP 800-63 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-01 | Token storage governs exposure of non-human bearer credentials. |
| NIST CSF 2.0 | PR.AC-1 | Identity proof and session access both depend on controlled authenticator handling. |
| NIST SP 800-63 | AAL2 | Bearer token handling affects session assurance and replay resistance. |
| NIST Zero Trust (SP 800-207) | PR.AC-4 | Zero trust requires reducing trust in stored credentials and session artifacts. |
| OWASP Agentic AI Top 10 | LLM-04 | Client-held tokens are easy targets for autonomous exploitation or tool chaining. |
Treat token storage as part of the authentication assurance design, not post-login plumbing.
Related resources from NHI Mgmt Group
- Why do identity signals matter in data security policy decisions?
- How can security teams evaluate whether a React framework supports good identity governance?
- How should security teams decide whether JIT access is safe for non-human identities?
- What is the difference between code scanning and runtime identity monitoring?
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on August 19, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org