Insights · Nov 7, 2026 · 4 min read · FAQ

Keeping users signed in to your SaaS: sessions or JWTs?

A session can be ended on the server at once; a JWT stays valid until it expires. How to choose, and the cookie settings that keep either one safe.

SESSIONS OR JWTSKeeping users signed in SELLWRIGHT

After someone signs in, your SaaS has to know it is still them on every request. There are two common ways to do it: a server-side session or a signed token such as a JWT. The choice decides how fast you can sign someone out, what a stolen laptop can still do, and what one script injection bug can leak.

What is the difference between a session and a JWT?

A session keeps the facts on your server; a JWT carries them inside the token. With a session, the browser holds only a random ID in a cookie, and the user and expiry sit in your session store. OWASP says that ID must be meaningless, with no personal data in it, and come from a cryptographically secure random generator.

A JWT, defined in RFC 7519, is a compact set of claims, such as the user, the issuer and the expiry, signed so any server holding the key can check it without a database lookup. Signing is not encryption: OWASP points out the payload is only base64url encoded, so anyone with the token can read every claim.

There are really two decisions here: what the credential is, and where it lives. A JWT can sit in a cookie too.

Why is signing out harder with JWTs?

Because a session can be deleted on the server at once, while a signed JWT stays valid until it expires. RFC 7519 says a token must not be accepted on or after its exp time, and nothing in the token ends it sooner. OWASP's JWT Cheat Sheet notes that JWTs are often suggested for "stateless" sessions, and that this use is frowned upon. If you use them anyway, narrow the gap:

  • Short lifetimes. OWASP notes a short expiration time limits how long a stolen token can be reused.
  • Refresh tokens with rotation. RFC 9700, the IETF's OAuth security best practice, says refresh tokens let a server issue short-lived access tokens. With rotation, each refresh returns a new refresh token and invalidates the old one; if an old one turns up again, the server revokes the active one.
  • A denylist of revoked tokens, keyed on jti and iss, not on the raw token or its hash, which OWASP warns against. That is a lookup on every request, which is what a session does anyway.

Either way, fix the accepted algorithms in code, never accept "alg":"none", and check exp, iss and aud.

Where should the session ID or token live?

In a cookie marked HttpOnly, Secure and SameSite, named with the __Host- prefix, and never in localStorage. OWASP's Session Management Cheat Sheet says not to keep session IDs, JWTs, refresh tokens or any credential in localStorage or sessionStorage, because one XSS flaw discloses every token. Its alternatives are such a cookie or a backend-for-frontend that holds tokens on the server. Keep IDs out of URLs too, where they leak through logs, history and the Referer header.

Set-Cookie: __Host-session=<random id>; Path=/; Secure; HttpOnly; SameSite=Strict
  • HttpOnly stops JavaScript reading the cookie through document.cookie.
  • Secure means it only travels over HTTPS.
  • SameSite controls whether it goes with cross-site requests. OWASP prefers Strict, accepts Lax, and says not to rely on browser defaults. With Lax, make sure no GET request changes data.
  • __Host- makes the browser reject the cookie unless it is Secure, has no Domain and uses Path=/, so a subdomain cannot set or override it. OWASP recommends it for session IDs.

How long should a session last, and when should the ID change?

Set an idle timeout and an absolute timeout, enforce both on the server, and issue a new ID at every sign-in. OWASP gives common idle timeouts of 2 to 5 minutes for high-value applications and 15 to 30 minutes for low-risk ones, and 4 to 8 hours as an absolute limit for an app used through an office day.

The new ID prevents session fixation, where an attacker plants a known ID in someone's browser and waits for them to log in. OWASP requires regenerating it after any privilege change, including login, password changes and switching to an admin role.

What should "sign out of all devices" do?

End every session the user has on the server, not just the cookie in front of them. OWASP notes that deleting a cookie does not invalidate a stolen copy, and recommends letting users see their active sessions, get alerts about concurrent sign-ins and end sessions remotely.

With server sessions that is one delete. With JWTs, revoke the refresh tokens, then denylist or wait out the access tokens already issued. Offer it after a password reset too: OWASP's Forgot Password Cheat Sheet suggests asking whether to end all existing sessions, or ending them automatically.

Which one fits your product?

Server sessions, for most SaaS web apps where the front end and API share your domain. Instant logout and sign out everywhere come almost free, which is why they are our default.

JWTs earn their place when another service must verify users without reaching your session store, or when sign-in comes through an OpenID Connect provider, whose ID tokens are JWTs. Even then, keep them short-lived and out of localStorage.

Where to start

List every place your app creates, checks and ends a sign-in, and hold each against the points above. Our web app and SaaS development service builds this in from the start, and roles and permissions in a SaaS app covers what a signed-in user may do next.

FAQ

Frequently asked questions

Are JWTs more secure than session cookies?

Not by format alone. A JWT's signature stops anyone changing its claims, but whoever holds the token can read those claims and use it until it expires. A session ID reveals nothing and can be ended on the server at once. What decides safety is where the credential is stored, how long it lives and whether you can revoke it.

Do we still need CSRF protection with SameSite cookies?

In most apps, yes. OWASP treats SameSite as defence in depth rather than a replacement for CSRF tokens. Browser defaults differ, Lax still sends cookies on top-level GET navigations, and SameSite counts every subdomain of your domain as the same site. Keep a CSRF token, or a custom request header for API calls, on every request that changes data.

Can we offer a "remember me" option?

Yes, as a longer absolute timeout rather than an endless session. Use a persistent cookie with Max-Age, renew the session ID on a schedule, and ask for the password again before changes to critical details such as the email address or password, which OWASP recommends. Show remembered devices on the account page so users can end them.

How should session data be stored on the server?

In a store only your application can reach, with access restricted and backups encrypted. OWASP adds that anyone who can read the store can reuse unexpired IDs. If that is a risk you plan for, split the ID into a lookup part and a secret part, and store only a hash of the secret.

Should a session be tied to the user's IP address?

Use the IP address and browser details as warning signs, not hard locks. OWASP recommends binding sessions to properties such as the client IP and User-Agent, so that a sudden change can trigger an alert or end the session. It also warns that an attacker on the same network, or copying the same User-Agent, can get past these checks.

What should we log about sessions?

The creation, renewal and end of each session, sign-ins and sign-outs, privilege changes, timeouts and invalid session activity, as OWASP's Session Management Cheat Sheet lists. Never write the raw session ID or token into logs. OWASP suggests logging a salted hash of the ID instead, which still lets you follow one session through the logs.

Next step

Ready for a website that sells?

Book a short call. We will look at your current site, agree what matters most and send a written scope with a fixed quote.

Book a callOr write to hello@sellwrightstudio.com