-
Notifications
You must be signed in to change notification settings - Fork 474
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
Use same leeway for exp
and nbf
when parsing JWT
#1312
Conversation
lib/shopify_api/auth/jwt_payload.rb
Outdated
@@ -73,8 +73,7 @@ def ==(other) | |||
|
|||
sig { params(token: String, api_secret_key: String).returns(T::Hash[String, T.untyped]) } | |||
def decode_token(token, api_secret_key) | |||
JWT.decode(token, api_secret_key, true, | |||
{ exp_leeway: JWT_EXPIRATION_LEEWAY, algorithm: "HS256" })[0] | |||
JWT.decode(token, api_secret_key, true, leeway: JWT_EXPIRATION_LEEWAY, algorithm: "HS256")[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to rename the constant to JWT_LEEWAY
since it doesn't only apply to expiration anymore, but it's a public constant and might make this a breaking change, so I decided to keep it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can always alias it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah good call, I'll do that then 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
lib/shopify_api/auth/jwt_payload.rb
Outdated
@@ -73,8 +73,7 @@ def ==(other) | |||
|
|||
sig { params(token: String, api_secret_key: String).returns(T::Hash[String, T.untyped]) } | |||
def decode_token(token, api_secret_key) | |||
JWT.decode(token, api_secret_key, true, | |||
{ exp_leeway: JWT_EXPIRATION_LEEWAY, algorithm: "HS256" })[0] | |||
JWT.decode(token, api_secret_key, true, leeway: JWT_EXPIRATION_LEEWAY, algorithm: "HS256")[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can always alias it
Description
Right now we specify a leeway of 10 seconds when validating JWT payload expiration, but no leeway for
nbf
(not valid before). Theshopify-api
JS library does allow forclockTolerance
in both fields, and I think it makes sense for the Ruby gem to do the same.How has this been tested?
I added unit tests.
Checklist: