Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax restrictions on "jti" claim verification #113

Merged
merged 1 commit into from
Oct 30, 2015

Conversation

lwe
Copy link
Contributor

@lwe lwe commented Oct 30, 2015

The RFC has the following to say about the "jti" claim:

The "jti" (JWT ID) claim provides a unique identifier for the JWT. The identifier value MUST be assigned in a manner that ensures that there is a negligible probability that the same value will be accidentally assigned to a different data object; if the application uses multiple issuers, collisions MUST be prevented among values produced by different issuers as well. The "jti" claim can be used to prevent the JWT from being replayed. The "jti" value is a case- sensitive string. Use of this claim is OPTIONAL.
https://tools.ietf.org/html/rfc7519#section-4.1.7

The current implementation expects that the jti is built as:

MD5( secret + ":" + iat )

anything else is not considered a valid jti. There are several issues with the current implementation:

  1. secret + ":" + iat is not exactly collision safe :) using random UUIDs is safer I'd say.
  2. It was only verified when it was present in the payload, so it was skipped when it was missing from the payload
  3. In the RFC there are no rules defined on how the "jti" claim should be validated

This pull request simply relaxes the verification of the "jti" claim to be present. This is in line with other implementations like the one for Java or Python. (FYI, there are other implementations that perform additional checks, the one seen most common is to verify against a fixed value supplied in the verify call).

It is my opinion that the library should just provide basic validation and make no additional assumption about the jti. Any additional verification / validation (e.g. replay checks, value checks) must be checked by the application and should be out of the scope for the library.

PS: Yes, one could argue about having the option to supply an expected value for the "jti" claim, but this is IMO not really reasonable, because it (should) change for every JWT generated. So it's not something quasi-static like e.g. the issuer or audience.

The RFC has the following to say about the "jti" claim:

> The "jti" (JWT ID) claim provides a unique identifier for the JWT.
> The identifier value MUST be assigned in a manner that ensures that
> there is a negligible probability that the same value will be
> accidentally assigned to a different data object; if the application
> uses multiple issuers, collisions MUST be prevented among values
> produced by different issuers as well.  The "jti" claim can be used
> to prevent the JWT from being replayed.  The "jti" value is a case-
> sensitive string.  Use of this claim is OPTIONAL.
> -> https://tools.ietf.org/html/rfc7519#section-4.1.7

The current implementation expects that the `jti` is built as:

  MD5( secret + ":" + iat )

anything else is not concidered a valid `jti`. There are several issues
with the current implementation:

1. `secret + ":" + iat` is not exactly collision safe :) using random
   UUIDs is safer I'd say.
2. It was only verified when it was present in the payload, so it was
   skipped when it was missing from the payload
2. In the RFC there are no rules defined on how the "jti" claim should
   be validated

This pull request simply relaxes the verification of the "jti" claim
to be present. This is in line with other implementations like the
one for Java or Python. (FYI, there are other implementations that
perform additional checks, the one seen most common is to verify
against a value supplied in the `verify` call)

It is my opinion that the library should just provide basic validation
and make no additional assumption about the "jti" claim. Any additional
verification / validation (e.g. replay checks, value checks) must be
checked by the application and should be out of the scope for the library.
@review-ninja
Copy link

ReviewNinja

aj-michael added a commit that referenced this pull request Oct 30, 2015
Relax restrictions on "jti" claim verification
@aj-michael aj-michael merged commit 6c84213 into jwt:master Oct 30, 2015
@aj-michael
Copy link
Member

Thanks @lwe, this was a blatant oversight on our part.

@excpt excpt added this to the Version 1.5.3 milestone Nov 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants