CWE-613OWASP A07:2021OWASP API2:2023CWE-384

CWE-613: Insufficient Session Expiration

Sessions or tokens stay valid too long or never expire, so a stolen or stale credential keeps working long after it should.

Also known as: Sessions that never expire, Long-lived tokens, Missing session timeout

Risk

Usually medium to high. A session that never expires widens the window for a stolen token, and sessions that survive logout or password change let a compromised credential persist indefinitely.

Definition

What it is

CWE-613 is the failure to end a session or token after an appropriate time or event. It covers sessions with no idle or absolute timeout, tokens that stay valid for months, and sessions that are not invalidated on logout or password change. The longer a credential lives, the longer a stolen copy keeps working and the more value it has to an attacker. Expiration must be enforced server-side, because a token the server still accepts is valid no matter what the client does with it.

Use-cases

How it shows up in real code

Session never times out

A logged-in session has no idle or absolute expiry. A token copied from an abandoned device still authenticates weeks later.

Logout does not invalidate

Clicking log out only clears the cookie in the browser while the server still accepts the token. An attacker who captured it earlier stays logged in.

Password change leaves sessions live

A user changes their password after a scare, but existing sessions are not revoked. The attacker's stolen session continues unaffected.

Long-lived API token

An API token is issued with a multi-year expiry and no rotation. Once leaked in a log or repo, it grants access for years.

AI risk

Why AI-generated code has increased the exposure

  • Assistants optimize for a session that keeps the user conveniently logged in, so they set a long or absent expiry rather than a short, security-minded one.
  • Training examples issue a token and move on, rarely showing idle timeouts or revocation on logout, so the model omits both.
  • The model cannot see the session store or revocation list, so it treats logout as a client-side cookie clear and never invalidates server-side.
  • When scaffolding auth, the assistant generates token issuance but not the expiry policy or the password-change revocation that should accompany it.
  • Generated API tokens often default to very long lifetimes with no rotation, since a longer-lived token is simpler and never breaks a demo.

Vibe coding

How vibe coding amplifies the risk

  • Vibe coding ships whatever expiry the assistant chose, and an app that stays logged in forever feels like a feature, not a flaw.
  • The skipped review is where someone would ask what is the session timeout and does logout actually revoke it.
  • A prototype built to never log you out is promoted to production, carrying its unlimited sessions with it.
  • The problem is invisible in local and demo testing because nobody waits long enough, or tries a stolen token after logout, to see the session still works.
  • As a vibe-coded product grows and tokens leak into logs or shared repos, the never-expiring sessions turn each leak into long-term access.

Detection

How to find it

  • Check whether sessions have both an idle timeout and an absolute maximum lifetime, and whether API tokens expire at all.
  • Log in, log out, then replay the old session server-side to confirm logout actually invalidates it.
  • Change a password and confirm existing sessions are revoked rather than left active.
  • Review token issuance for lifetime, rotation, and a server-side revocation mechanism.

Remediation

How to fix it

  • Set a sensible idle timeout and an absolute session lifetime, enforced on the server, not only in the client.
  • Invalidate the session server-side on logout so a captured token stops working immediately.
  • Revoke all active sessions on password change or credential reset, and offer a sign out everywhere control.
  • Issue short-lived access tokens with refresh and rotation instead of long-lived static tokens.
  • Maintain a server-side session or token store that can revoke a credential on demand, and audit long-lived tokens regularly.

Frequently asked questions

What is CWE-613 (insufficient session expiration)?
CWE-613 is when sessions or tokens stay valid too long or never expire, including sessions that survive logout or a password change, so a stolen or stale credential keeps working long after it should. Because the server still accepts the token, the risk is independent of what the client does.
How have AI assistants and vibe coding increased the risk?
Assistants optimize for keeping the user conveniently logged in, so they set long or absent expiries and treat logout as a client-side cookie clear without server-side revocation. Vibe coding ships those defaults because the gap never shows up in a quick demo, so sessions that never expire reach production.
How do I fix insufficient session expiration?
Enforce idle and absolute timeouts on the server, invalidate sessions on logout, revoke all sessions on password change, and use short-lived access tokens with rotation backed by a revocation store.

Related weaknesses

Catch CWE-613 before you ship

Tethlyn Audit scans your codebase and its git history for CWE-613 and the rest of the authentication & session security class, then ranks each finding by real exploitability and data sensitivity.

See Tethlyn Audit