The choice looks like a technical detail until something goes wrong. An employee leaves, a password is reset, a role changes or an account is compromised, and the team discovers that existing tokens stay valid for hours because nothing on the server can cancel them. Or a growing product finds that its central session store has become a bottleneck.
For most web applications, server-side sessions in secure cookies are the simpler and safer default, and JWTs fit best as short-lived access tokens between services or for APIs, backed by refresh tokens or a revocation check, so access can be withdrawn quickly.
This article compares the two models, explains the revocation problem and five fixes, covers browser storage and refresh tokens, maps common scenarios to a choice and shows two delivered projects. It does not cover password hashing or multi-factor authentication.
Key takeaways
- Sessions are easy to revoke because the server holds the state. JWTs are easy to verify anywhere, but hard to cancel before they expire.
- Keep JWT access tokens short-lived, measured in minutes, and pair them with refresh tokens that the server can revoke.
- Avoid putting permissions inside long-lived tokens. Role changes should take effect on the next request.
- In browsers, store session IDs and tokens in Secure, HttpOnly cookies with SameSite set, and protect against cross-site request forgery.
- Rotate refresh tokens for browser and mobile clients, as the OAuth 2.0 security best practice requires.
- A multisite legal CMS kept permissions in a policy store with revocable tokens, so access changes apply at once across all firm websites.
How each model works
Session authentication
- The user signs in. The server checks the credentials and creates a session record with the user ID and session data.
- The browser receives a session ID. A random, unguessable value is stored in a cookie.
- Each request carries the cookie. The server looks up the session and knows who the user is.
- Sign-out deletes the session. The ID stops working immediately.
JWT authentication
- The user signs in. The server or identity provider issues a token signed with a private or shared key.
- The token carries claims. User ID, expiry time, issuer, audience and sometimes roles are encoded inside it.
- Each request carries the token. Any service with the verification key checks the signature and expiry, with no database lookup.
- Sign-out is harder. The token remains valid until it expires unless the system adds a revocation mechanism.
The format is defined in RFC 7519, which describes a JWT as a compact, URL-safe way to represent claims transferred between two parties.
JWT vs session compared
| Server-side session | JWT | |
|---|---|---|
| Where state lives | On the server, in memory, a database or a cache | Inside the token, held by the client |
| Verification | Lookup on each request | Signature check, no lookup needed |
| Revocation | Immediate, delete the session | Waits for expiry, unless extra checks are added |
| Size on each request | A short ID | Larger, grows with the claims |
| Across services and domains | Needs a shared session store or a central auth service | Any service with the key can verify |
| Typical use | Server-rendered sites and apps on one domain | APIs, mobile apps, service-to-service calls, identity providers |
| Main risk | Session store becomes a bottleneck or single point of failure | Stolen or outdated tokens keep working |

The revocation problem
A JWT is valid as long as its signature checks out and it has not expired. If a token lives for 24 hours and a user is removed at 9:00, the token still works until the next morning. The same applies to role changes: a token that says "admin" keeps saying it after the role is withdrawn. For many products that delay is unacceptable, especially for staff tools, financial actions and anything with customer data.
| Method | How it works | Revocation speed | Cost |
|---|---|---|---|
| Short-lived access tokens with refresh tokens | Access tokens expire in minutes, refresh tokens are stored and checked on the server | Within the access token's lifetime | Refresh logic in every client |
| Denylist of token IDs | Each token has a unique ID, and revoked IDs are checked on each request | Immediate | A fast lookup on every request |
| Token version per user | The user record holds a version number, and tokens with an older version are rejected | Immediate for all of a user's tokens | A lookup on every request |
| Opaque tokens with introspection | The client holds a random token, and services ask the auth server whether it is valid | Immediate | Calls to the auth server, usually cached briefly |
| Permissions checked at request time | The token proves identity only, and permissions come from a policy store | Immediate for permission changes | A permission lookup, usually cached |
Several of these add a lookup, which removes part of the reason for using JWTs. That is acceptable: the lookup can hit a fast cache, and the system gains control over access.
Storing tokens in the browser
- Prefer cookies over localStorage. Any script on the page, including one injected through a cross-site scripting flaw, can read localStorage. HttpOnly cookies cannot be read by scripts.
- Set the right attributes. The OWASP Session Management Cheat Sheet recommends the Secure, HttpOnly and SameSite attributes, the __Host- prefix for session cookies and regenerating the session ID after login to prevent session fixation.
- Protect against CSRF. Cookies are sent automatically, so state-changing requests need SameSite settings and anti-CSRF tokens.
- Set timeouts. Use both an idle timeout and an absolute session lifetime, enforced on the server.
- Use a backend for single-page apps. A small server component can hold tokens and give the browser a session cookie, so tokens never reach JavaScript.
Refresh tokens done safely
Refresh tokens let clients get new access tokens without signing in again, so they are valuable to attackers. The IETF's Best Current Practice for OAuth 2.0 Security, RFC 9700, requires refresh tokens issued to public clients, such as browser and mobile apps, to be sender-constrained or rotated. With rotation, each use returns a new refresh token and invalidates the old one, and reuse of an old token signals theft and should revoke the whole chain.
Not sure your login and token setup would survive a security review? We audit and rebuild authentication, sessions and permissions in existing products.
Explore IT outsourcingWhich to use, by scenario
| Scenario | Usually the better choice |
|---|---|
| Server-rendered website or app on one domain | Server-side sessions in secure cookies |
| Single-page app with its own backend on the same site | Sessions, or tokens held by the backend with a session cookie for the browser |
| Mobile app calling your API | Short-lived access tokens with rotated refresh tokens in secure device storage |
| Microservices behind a gateway | Short-lived JWTs issued at the gateway, verified by each service |
| Several brands or domains with one login | An identity provider using OpenID Connect, with local sessions on each site |
| Public API for partners | API keys or OAuth client credentials with short-lived tokens |
Two projects where token design mattered
Revocable access across a multisite legal CMS
A US law firm runs several websites on Verba, its in-house content management system. Fixed roles could not keep up with more sites and content types. A .wrk team replaced them with a policy, resource and action permission model, similar in style to cloud provider access policies, with revocable tokens. Permissions live in the policy store and are checked when a request arrives, so they are never frozen into a JWT, and an administrator's change applies immediately across every site. The authentication paths shipped with full test coverage. Read the Verba CMS case study, and our comparison of RBAC and ABAC for how to design the permission model.
One sign-in for three media brands
Three US B2B media brands share one Auth0 identity provider. Passwords were entered on each brand's own domain, which broke password managers, and readers had to fill in long forms to register for each webcast. A .wrk team moved password entry to the identity provider's domain in a two-step flow, email first and password second, and connected webcast registration to the existing session, so signed-in readers register in one click. Read the multi-domain SSO case study and our guide to single sign-on across multiple domains.

Common mistakes
- Long-lived JWTs with no revocation. Removed users and stolen tokens keep working for days.
- Roles and permissions baked into tokens. Access changes wait for the token to expire.
- Tokens in localStorage. One cross-site scripting bug exposes every signed-in user.
- Accepting unsigned or wrongly signed tokens. Libraries must reject the "none" algorithm and verify the expected algorithm, issuer and audience.
- Refresh tokens without rotation. A stolen refresh token gives an attacker access indefinitely.
- No sign-out everywhere. Users and administrators need a way to end all sessions after a password reset or a lost device.
Frequently asked questions
What is the difference between JWT and session authentication?
Session authentication stores the signed-in state on the server and gives the browser a random ID. JWT authentication gives the client a signed token containing the user's identity and claims, which services verify without a lookup.
Is JWT more secure than sessions?
Neither is more secure by default. Sessions are easier to revoke and simpler to store safely in browsers. JWTs suit distributed systems but need short lifetimes, careful storage and a revocation mechanism to match the control sessions give.
How do you revoke a JWT?
Keep access tokens short-lived and revoke the refresh token, or check each token against a denylist of revoked token IDs, a per-user token version or an introspection endpoint on the auth server.
Where should I store a JWT in the browser?
Prefer an HttpOnly, Secure cookie with SameSite set, or keep tokens on a backend that gives the browser a session cookie. Avoid localStorage, which any script on the page can read.
When should I use JWT authentication?
Use JWTs as short-lived access tokens for APIs, mobile apps and calls between services, and when an identity provider issues tokens for several applications. For a typical web app on one domain, sessions are usually simpler.
To sum up
Use server-side sessions in secure cookies for most web applications, and use JWTs as short-lived access tokens for APIs, mobile apps and services. Whatever you choose, make revocation fast: rotate refresh tokens, check permissions at request time, keep tokens out of JavaScript and give users and administrators a way to sign out everywhere.
.wrk builds and secures web platforms for companies in the US and Europe, including authentication, single sign-on and permission systems for multisite products.
Planning a login, SSO or permissions overhaul? Tell us about your apps, domains and users, and we will propose an authentication design.
Explore IT outsourcing