← Java / Spring · Contents

JAVA-048 / Intermediate

Not validating JWT expiry (exp) or audience (aud)

A07:2021 Identification and Authentication Failures · CWE-613 Insufficient Session Expiration

Why is this a problem?

Stolen tokens may remain valid indefinitely or be reused in another service.

How to fix it

java
Jwts.parser().verifyWith(key).requireAudience(AUD).requireIssuer(ISS)
    .clockSkewSeconds(30).build().parseSignedClaims(token);

Further reading