Subscribe to the Non-Human & AI Identity Journal

How should security teams implement JWT authentication safely in web applications?

Security teams should validate every token on every request, keep claims minimal, store tokens in the least exposed client context available, and enforce short expiry with a clear renewal path. They also need a revocation mechanism for compromise, offboarding, and role changes. Without those controls, JWTs become portable bearer credentials rather than controlled access artefacts.

Why This Matters for Security Teams

JWTs are often adopted for speed, but they become risky when teams treat them as set-and-forget bearer tokens. A signed token proves integrity, not ongoing trust. If a token is stolen, replayed, or over-scoped, an attacker can move through the application until expiry unless validation, storage, and revocation are designed correctly. That is why JWT handling should be mapped to broader identity governance, including the control discipline reflected in the NIST Cybersecurity Framework 2.0 and the lifecycle issues described in Ultimate Guide to NHIs.

The practical failure is rarely the signature algorithm alone. Teams more often get tripped up by excessive claims, weak client-side storage, long token lifetimes, and no reliable way to invalidate tokens after compromise or role change. NHIMG research shows that 71% of NHIs are not rotated within recommended time frames and 80% of identity breaches involved compromised non-human identities such as service accounts and API keys, which is a useful warning sign for JWT-heavy systems too. In practice, many security teams encounter token abuse only after an incident has already spread beyond the original session boundary.

How It Works in Practice

Safe JWT use starts with treating the token as a portable credential that must be validated on every request. That means checking the issuer, audience, signature, expiry, and any nonce or token-binding signals your architecture supports. Claims should be minimal and specific to the application, because oversized claims increase exposure if the token is replayed or logged. For implementation guidance, align the app’s identity controls with the NIST Cybersecurity Framework 2.0 and use lifecycle discipline consistent with Ultimate Guide to NHIs.

Operationally, security teams should prefer the least exposed client context available. In browser-based applications, current guidance suggests HttpOnly, Secure cookies with CSRF protections are often safer than exposing tokens to JavaScript, but there is no universal standard for every architecture. For APIs and service-to-service traffic, short-lived access tokens should be paired with a clear renewal path and server-side revocation controls. Teams should also centralise token issuance rules, log token use for anomaly detection, and ensure offboarding or privilege changes trigger immediate invalidation of active sessions.

  • Validate every token at the API boundary, not only at login.
  • Keep claims small, purpose-specific, and non-sensitive.
  • Use short expiry windows and renew only when the session is still legitimate.
  • Store tokens in the least exposed client context that fits the app model.
  • Maintain revocation for compromise, offboarding, and role changes.

These controls tend to break down in single-page apps that rely on long-lived refresh flows without backend session state because stolen tokens can persist beyond the intended trust window.

Common Variations and Edge Cases

Tighter token controls often increase operational overhead, requiring organisations to balance user experience against replay resistance and revocation speed. That tradeoff matters most when applications span browsers, mobile devices, partner integrations, and machine-to-machine workflows. A browser app may tolerate frequent renewal prompts, while a background integration usually needs a different renewal and rotation model. The current guidance suggests not forcing one JWT pattern across all workloads.

Edge cases also matter. If a JWT is used only as an internal assertion between trusted services, the acceptable storage and renewal pattern may differ from customer-facing authentication. If the token carries role claims, teams should expect stale authorisation until the next issue cycle unless revocation is enforced. If the app depends on third-party IdPs, the real risk often sits in session duration, claim mapping, and logout propagation rather than in JWT parsing itself. For broader identity context, NHIMG research on ASP.NET machine keys RCE attack shows how weak credential handling in web applications can turn into full application compromise.

Where JWT guidance breaks down most often is in federated environments with multiple issuers and uneven revocation support, because token trust becomes fragmented across systems that do not share the same session state.

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 address the attack and risk surface, while NIST CSF 2.0 and NIST SP 800-63 set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
OWASP Non-Human Identity Top 10 NHI-03 JWT expiry, rotation, and revocation are core non-human credential lifecycle issues.
NIST CSF 2.0 PR.AC-4 Token validation and least-privilege access align with access control governance.
NIST SP 800-63 Session and authentication assurance help distinguish issuance from continued trust.

Set short JWT lifetimes, automate rotation, and revoke tokens immediately on compromise or offboarding.