RFC 7519: JWT: Signed claims in JSON format

Summary

In May 2015, Michael Jones, John Bradley and Nat Sakimura defined the JSON Web Token, JWT for short, in RFC 7519, a compact and URL-safe format for claims about a user or service. A JWT is signed with JWS or encrypted with JWE and consists of base64url-encoded parts separated by dots. The format became the basis of OpenID Connect and many API logins but also brought its own family of typical implementation errors.

Claims in a token

A JWT contains claims, that is, statements such as who issued the token (iss), about whom (sub), for which recipient (aud), from when (nbf) and until when (exp) it is valid, and when it was created (iat). A unique identifier (jti) helps against reuse. The recipient can verify the token without asking the issuer.

Therein lie both strength and weakness: self-contained tokens relieve central services but cannot easily be revoked while they are valid. RFC 7519 suggests pronouncing it like the English word jot.

The algorithm trap

RFC 7519 also allows unsecured JWTs with the algorithm none. Libraries that took the algorithm from the token could thus be fooled with unsigned tokens or tokens signed with the wrong method.

In February 2020, RFC 8725 collected these experiences as a Best Current Practice: configure algorithms explicitly instead of reading them from the token, verify all cryptographic steps, use strong keys and design tokens for different purposes so that they cannot be confused.

Ideas

  • A JWT carries signed or encrypted claims.
  • Three base64url parts separated by dots form the compact form.
  • exp and nbf limit validity in time.
  • aud binds a token to a specific recipient.
  • Self-contained tokens are hard to revoke early.
  • The algorithm none produces unsecured tokens.

Insights

  • Flexibility in cryptography became the main attack surface; secure libraries deliberately restrict it.
  • A token that can be verified without a query shifts the problem from the server to short lifetimes and clean key management.

Facts

  • RFC 7519 appeared in May 2015.
  • Registered claims are iss, sub, aud, exp, nbf, iat and jti.
  • RFC 8725 from February 2020 describes Best Current Practices for JWT.
  • OpenID Connect uses JWTs as the format for ID tokens.

References

Critique

  • RFC 7519 allows unsecured tokens with none and leaves algorithm checking to the application; this is what made the well-known confusion attacks possible in the first place.

Remarks

  • By default JWTs are only signed, not encrypted; anyone who sees a token can read its claims.

Recommendations

  • Fix the permitted algorithms on the server and reject none.
  • Check iss, aud, exp and the signature completely on every verification.
  • Choose short lifetimes and use refresh tokens that can be revoked for longer sessions.

Read the RFC at the RFC Editor

Search the Web Archive

Found a mistake or have something to add? Get in touch.