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

Add ignoreExpiry(), ignoreNotBefore() and ignoreSignature() to JwtPa… #80

Closed
wants to merge 1 commit into from

Conversation

ryanflegel
Copy link

Add ignoreExpiry(), ignoreNotBefore() and ignoreSignature() to JwtParser to skip validations when parsing JWT.

I need to parse some information out of the token, but I'm not too concerned about the validity of the token.

In particular, I'm extracting the subject for logging and the token will either already be validated (I don't have the key) and I would still like to log the username (subject) in case of any errors, even if it can't be trusted.

…rser to skip validations when parsing JWT.
@ryanflegel
Copy link
Author

Looks like the CI build failed due to something environment related -- is there a way to run it again?

@lhazlewood
Copy link
Contributor

Yeah, I'm fixing that now (Open JDK 7 was core dumping when Cobertura was enabled). That said, I don't think the current implementation approach is the right way to go: there are different validations that occur during parsing and we probably shouldn't add an ignore* method for every rule in existence.

Maybe something singular like validate(boolean validate) and if false, all validation is disabled. Thoughts?

@ryanflegel
Copy link
Author

Yeah, you're probably right -- I was following the pattern used by require*. I think there are two main types of validations that should be able to be selectively ignored. The first is the signature validation and the second is the claims validations (iat, exp, nbf, etc).

@ryanflegel
Copy link
Author

After taking a closer look, these seem to be the only validations that can't be configured, so I don't really see the list growing.

With respect to claims validations, there are currently two types:

  1. exp and nbf which are automatically validated based on current datetime.
  2. Any claim can be validated based on equality with require* methods. This includes exp and nbf.

I think configuring exp & nbf are a current gap in the current API, since require* only validates by equality and even then, the "nbf <= now < exp" that can't be disabled/configured. I see there are also a couple PRs around clock skew which is also a result of that. Perhaps the new API should address both these issues as one?

Just brainstorming here, but maybe instead of requireExpiry() and requireNotBefore(), they could be replaced by a more advanced validator interface. Here's an example of what i mean with some factory methods to keep it readable:

// Default would be equivalent to current validation: nbf <= now < exp

// Disables validation completely (my use case)
validateExpiry(DateValidator.disabled());

// Allow for a skew of 15 seconds: (nbf - 15s) <= now < (exp + 15s)
validateExpiry(DateValidator.allowClockSkew(15, TimeUnit.Seconds))

// Equivalent to requireExpiry(myDate)
validateExpiry(DateValidator.equalTo(myDate));

With respsect to signature validations, I think it still makes sense to have a validateSignature(boolean) and keep this independently configurable from claims validations.

@ryanflegel ryanflegel changed the title Add ignoreExprity(), ignoreNotBefore() and ignoreSignature() to JwtPa… Add ignoreExpiry(), ignoreNotBefore() and ignoreSignature() to JwtPa… Mar 19, 2016
@jd-carroll
Copy link

What is the status of this PR?

marciocamurati pushed a commit to marciocamurati/jjwt that referenced this pull request Sep 16, 2016
@selimok
Copy link

selimok commented Sep 27, 2016

Hi, are there any decision to merge this change into master?

As part of our token expiration strategy, we create tokens with short life spans and re-create new tokens if needed. To do this in more convenient way, we need aforementioned ignore methods while parsing.

Thanks.

@lhazlewood
Copy link
Contributor

Quite possibly - we'll double check since there seems to be more interest.

@nvasilescu
Copy link

I need this also. To be able to read claims from an expired token.

@emeraquino
Copy link

Any news regarding the status of this of PR?

@djensen47
Copy link

djensen47 commented Jan 23, 2020

Is there any other way to get claims without checking expiration or signature?

@lhazlewood
Copy link
Contributor

Closing just as a matter of housekeeping - this will be implemented/tracked under #474

@lhazlewood lhazlewood closed this Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants