JWT No Expiry

JWT tokens signed without an expiration

warningSecurityjwt-no-expiry

Why this matters

A JWT without an expiration never becomes invalid. If it's stolen, the attacker has permanent access — there's no way to revoke it without changing the signing key for everyone.

Example

Flaggedlib/session.ts
import jwt from "jsonwebtoken";

const token = jwt.sign(
  { userId: user.id, role: user.role },
  process.env.JWT_SECRET!
);
Fixedlib/session.ts
import jwt from "jsonwebtoken";

const token = jwt.sign(
  { userId: user.id, role: user.role },
  process.env.JWT_SECRET!,
  { expiresIn: "1h" }
);

How to fix

Always set an expiresIn (or exp claim) when signing JWTs. Use short-lived access tokens (15min-1hr) with refresh tokens for longer sessions.

Reference

In the output
Findings carry "ruleId": "jwt-no-expiry" in --json and the same id in SARIF and in the terminal.
Silence one line
// prodlint-disable-next-line jwt-no-expiry
Silence a whole file
// prodlint-disable jwt-no-expiry at the top of the file
How it works
Reads the syntax tree, with a text fallback for files that don't parse. Source on GitHub