Skip to content
Security Article

Why JWTs Are a Security Anti-Pattern for Sessions

Relying on stateless JSON Web Tokens for persistent user sessions introduces severe security risks and architectural complexity.

Ji-ho Choi
Ji-ho Choi
Security & Cloud Editor · Jun 16, 2026 · 4 min read

The developer community has widely adopted JSON Web Tokens (JWTs) as a default mechanism for handling user sessions. However, using JWTs to keep users logged in is an architectural anti-pattern. JWTs were not designed for persistent session management, and using them in this manner introduces significant security vulnerabilities while failing to deliver the promised benefits of statelessness.

For the vast majority of web applications, traditional stateful session cookies remain the superior, more secure choice. Understanding why requires looking closely at the mechanics of session revocation, the inherent flaws of the JWT specification, and how enterprise architectures actually handle authentication.

The Illusion of Stateless Sessions

A primary argument for JWTs is that they enable "stateless" authentication, theoretically removing the need for a database lookup on every API request. But truly stateless session management is a security liability.

In any real-world application, security requirements dictate the ability to immediately revoke a session. This is necessary when a user logs out, changes their password, or is banned by an administrator. Because a JWT is self-contained and cryptographically signed, the server cannot invalidate it prematurely without maintaining state.

To revoke a JWT before its expiration, the system must maintain a database or cache of revoked tokens. Once a data store is introduced to track token state, the architecture is no longer stateless. If an application must maintain a data store to handle tokens securely, it is far more efficient and secure to store the session data directly in a traditional database rather than managing a complex token-revocation list.

Inherent Flaws in the JWT Specification

Security experts widely distrust the JWT specification itself. The design of the specification has historically introduced critical vulnerabilities, including flaws in the original spec that made it possible to forge or create fake tokens.

Beyond the specification's cryptographic pitfalls, the way developers store JWTs in the browser introduces severe client-side risks. Developers frequently store JWTs in localStorage or sessionStorage. Storing authentication credentials in these locations exposes them directly to Cross-Site Scripting (XSS) attacks. Unlike standard session cookies, which can be protected with the HttpOnly and Secure flags to prevent client-side script access, tokens in local storage are easily exfiltrated if an attacker successfully injects malicious JavaScript into the application.

Furthermore, the JWT specification is designed specifically for very short-lived tokens, typically lasting five minutes or less. Using them for persistent user sessions requires extending their lifespan far beyond this window, significantly widening the opportunity for an attacker to exploit a stolen token.

Misinterpreting Enterprise Architectures

Proponents of JWTs often point to tech giants, claiming that organizations like Google rely on them for authentication. This is a misunderstanding of how enterprise architectures operate.

Google does not use JWTs to maintain active user sessions in the browser; instead, they rely on traditional cookie-based sessions. Google utilizes JWTs strictly as transport mechanisms for Single Sign-On (SSO) operations, allowing a login session on one host to be securely transferred to another. These organizations possess the specialized security resources required to implement and maintain these complex, highly customized transport mechanisms safely. For standard web applications, mimicking this architecture for basic session management introduces unnecessary risk.

Safer Paths: Stateful Cookies and PASETO

For the vast majority of web applications, traditional session cookies remain the most secure and flexible option. If an application has users, it inherently manages state and typically relies on a database. This database can easily store session identifiers.

For modular environments like Express, developers can implement session middleware paired with a database connector to manage sessions using robust backends like PostgreSQL, MySQL, or SQLite.

If an application genuinely requires a short-lived, signed token for a specific, non-session use case, developers should look beyond the flawed JWT specification. PASETO (Platform-Agnostic Security Tokens) provides a modern, secure alternative designed specifically to eliminate the cryptographic pitfalls inherent in JWTs, ensuring that tokens are secure by default.

Sources & further reading

  1. Stop Using JWTs — gist.github.com
Ji-ho Choi
Written by
Ji-ho Choi · Security & Cloud Editor

Ji-ho covers the increasingly tangled overlap between cloud architecture and security, drawing on a background as a penetration tester to keep his reporting grounded in real-world attack paths. He never lets a vendor claim go unquestioned and insists that every buzzword come with a proof of concept.

Discussion 0

Join the discussion

Sign in or create an account to comment and vote.

No comments yet

Be the first to weigh in.

Related Reading