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

Reject seconds values that would cause overflow #583

Closed
jonalbertini opened this issue Mar 26, 2020 · 3 comments · Fixed by #601
Closed

Reject seconds values that would cause overflow #583

jonalbertini opened this issue Mar 26, 2020 · 3 comments · Fixed by #601
Milestone

Comments

@jonalbertini
Copy link

If seconds used with long max value, there will be an overflow because you put the value (long) multiplied by 1000 in another long...
in my case i got a negative value as result and the Math.max then return 0....

as I was expecting to have the max ClockSkew, I got the Min....

this.allowedClockSkewMillis = Math.max(0, seconds * MILLISECONDS_PER_SECOND);

@lhazlewood
Copy link
Contributor

lhazlewood commented Mar 27, 2020

I don't quite understand the problem. You shouldn't have overflow with any relevant value, correct? Clock skew should ideally be no more than 5 to 10 minutes at most (e.g. 300-600 seconds). Multiplying 300 * 1000 shouldn't ever cause overflow.

I'm curious - how did this happen? What was your input value?

@jonalbertini
Copy link
Author

jonalbertini commented Mar 30, 2020 via email

@lhazlewood
Copy link
Contributor

lhazlewood commented Apr 7, 2020

Test cases written without any insight into why an API exists, or to use the API in an unintended manner, will cause problems like this. In this case, these test cases are effectively using a feature of the library to avoid the designed purpose of the method - to account for clock skew during parsing. This method does not exist to allow parsing expired tokens, so the test is using it incorrectly.

If anything, a nicer solution is probably to reject any value greater than (Long.MAX_VALUE / 1000) to guarantee that overflow is not possible.

Until #308 is incorporated after 1.0 is released - where we can use a java.time.Duration instance instead of just milliseconds - enforcing an upper bound is probably the cleanest solution because it doesn't introduce another temporary method that will be immediately thrown out when we can use a Duration instead.

Thank you for the feedback and the issue!

@lhazlewood lhazlewood changed the title Beware of max values. Reject seconds values that would cause overflow Apr 26, 2020
@lhazlewood lhazlewood added this to the 0.11.2 milestone Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants