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

Claims Validation #287

Closed
wants to merge 4 commits into from
Closed

Conversation

jamesstonehill
Copy link
Contributor

@jamesstonehill jamesstonehill commented Sep 18, 2018

In an effort to make the claim validation a little more extendable and to fix this issue, I've added a ClaimsValidator class that is responsible for validating validatable claims.

I thought that it is a little inconsistent that we only validate the exp claim is an integer even though the JWT RFC mandates that all time (iat, nbf, and exp) claims "MUST be a number containing a NumericDate value".

@sourcelevel-bot
Copy link

Hello, @jamesstonehill! This is your first Pull Request that will be reviewed by Ebert, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information.

@@ -0,0 +1,11 @@
module JWT
CLAIMS = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use %i or %I for an array of symbols.

@@ -0,0 +1,11 @@
module JWT
CLAIMS = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Freeze mutable objects assigned to constants.

lib/jwt/claims_validator.rb Show resolved Hide resolved
lib/jwt/claims_validator.rb Show resolved Hide resolved
lib/jwt/claims_validator.rb Show resolved Hide resolved
@excpt excpt self-assigned this Sep 18, 2018
@excpt excpt self-requested a review September 18, 2018 21:30
@jamesstonehill jamesstonehill force-pushed the options-handling branch 2 times, most recently from 5937047 to 2aed55d Compare September 18, 2018 21:56
@jamesstonehill
Copy link
Contributor Author

@excpt seems like the specs are failing for 2.2 because of a dependency mismatch with openssl

@sourcelevel-bot
Copy link

Ebert has finished reviewing this Pull Request and has found:

  • 3 possible new issues (including those that may have been commented here).
  • 2 fixed issues! 🎉

But beware that this branch is 13 commits behind the jwt:master branch, and a review of an up to date branch would produce more accurate results.

You can see more details about this review at https://ebertapp.io/github/jwt/ruby-jwt/pulls/287.

Copy link
Member

@excpt excpt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

Copy link
Member

@anakinj anakinj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a nice addition, to separate the validation from the encoding logic.

Added one minor issue with the validation, might be worth checking out.

end

def validate
validate_exp if @payload[:exp]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to check that the key actually is present in the payload, this row is now checking if the value returned from the hash is thruthy.

I think this will not validate cases where exp is false or nil eg:

{ exp: false }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@jamesstonehill
Copy link
Contributor Author

jamesstonehill commented Jan 26, 2019

Switching branches to this one for a cleaner commit history. #295

@jamesstonehill jamesstonehill deleted the options-handling branch January 26, 2019 13:08
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.

Inconsistent handling of payload claim data types
3 participants