JWT No Expiry
JWT tokens signed without an expiration
warningSecurity
jwt-no-expiryWhy 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
lib/session.tsimport jwt from "jsonwebtoken";
const token = jwt.sign(
{ userId: user.id, role: user.role },
process.env.JWT_SECRET!
);lib/session.tsimport 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--jsonand 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-expiryat 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