jwt_tool icon indicating copy to clipboard operation
jwt_tool copied to clipboard

ValueError: year 53831 is out of range

Open j0eblow opened this issue 3 years ago • 7 comments

Traceback (most recent call last):
  File "/opt/jwt_tool/jwt_tool.py", line 2028, in <module>
    rejigToken(headDict, paylDict, sig)
  File "/opt/jwt_tool/jwt_tool.py", line 1291, in rejigToken
    comparestamps, expiredtoken = dissectPayl(paylDict)
  File "/opt/jwt_tool/jwt_tool.py", line 1185, in dissectPayl
    timestamp = datetime.fromtimestamp(int(paylDict[claim]))
ValueError: year 53831 is out of range

j0eblow avatar Nov 11 '21 20:11 j0eblow

I was able to resolve this issue by using the Arrow library and editing a few lines in jwt_tool.py. If anyone is interested in the solution, let me know.

j0eblow avatar Nov 12 '21 17:11 j0eblow

Sorry for the slow response. What was in your token to cause this error? Can you supply an example? If it's going to affect others I'll happily patch it. You can submit a PR if you have a fix.

ticarpi avatar Nov 12 '21 20:11 ticarpi

So I encountered the same or similar issue, it looks to be when the timestamps issued are in milliseconds vs seconds. Datetime wants the timestamp value in seconds.

In order to get it working with minimal effort I just caught the error if it happened and retried dividing the claim by 1000, not the most elegant though.

For testing 1639007079948 was the timestamp from my claim.

I'd think testcases that involve tampering with the timestamp would also fail server side though as well unless it was accounted for or changed back to milliseconds.

spacesedge avatar Dec 09 '21 01:12 spacesedge

I have run into this as well. The solution spacesedge suggested works for reading JWTs but clearly it's not enough if you need to tamper.

ghost avatar Feb 21 '22 14:02 ghost

Any solution for this?

DeserranoJorden avatar Nov 02 '22 10:11 DeserranoJorden

I was able to resolve this issue by using the Arrow library and editing a few lines in jwt_tool.py. If anyone is interested in the solution, let me know.

yes please.

scrambledeggnostic avatar Dec 27 '22 20:12 scrambledeggnostic

I fixed it by catching the exception and dividing the value by 1000. Replace line 1185 with the following code:

			try:
				timestamp = datetime.fromtimestamp(int(paylDict[claim]))
			except ValueError:
					ts = paylDict[claim] / 1000
					timestamp = datetime.fromtimestamp(ts)

Gilzy avatar Mar 16 '23 11:03 Gilzy