-
-
Notifications
You must be signed in to change notification settings - Fork 694
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
The token is not yet valid (iat). #814
Comments
Hi @AGaliciaMartinez , I request you take a look at the PR description to understand it better why we need to include this check and also check your code/token what's the current_time and issued_at time is to ensure the same. |
Different servers could have different time settings, especially when they are not connected to the internet, like a private network. Not every private network has a clock synchronization mechanism. |
In that cases we can use the UTC time as a standard time. Also for the time difference in clock synchronization we can use the leeway time to make it work. @auvipy any added inputs will be helpful here |
I've also encountered this issue, particularly in tests where the token is issued within a few milliseconds of when it gets used. The problem is that the Here is an example that used to succeed, but now raises an error: jwt.decode(jwt.encode({'iat': time.time()}, 'secret', algorithm='HS256'), 'secret', algorithms=['HS256']) I suggest either allowing full float calculations or casting the input |
we need to get rid of the type error |
It's yes and no, since most JWT libraries in other languages also support the An example could be, With this, |
We've also been hit by this bug, broke all our tests. Our 'iat' stores the current time as a float. |
Hi, @auvipy I hope this is something we all need to take a call on. |
One simple "fix" would be to cast iat = payload["iat"]
try:
iat = int(iat)
except ValueError:
raise InvalidIssuedAtError("Issued At claim (iat) must be an integer.") This would allow It is possible to use |
what if instead of: Line 190 in 0cfc097
we just did now = datetime.now(tz=timezone.utc).timestamp() Wouldn't that mostly address the issues seen? Anything else would be addressed by specifying a leeway when decoding. unsure if i'm missing anything else. |
@jpadilla your solution should work, I also got a few tests failing when upgrading pyjwt :
the value of «now» seems not to include milliseconds, because per timegm source code, it’s only seconds :
we could bypass this with a leeway of 1 second, but that’s a lot of leeway |
i don't think it's a good solutions. |
Hi. Solved it by simply deactivate the check with: options={"verify_iat":False} in decode:
|
will there be any tagged release with this fix? |
I took this advice and casted the payload I'm passing to 'iat' to int like this:
It worked for me. Thank you! (Although I will still watch this thread) |
Thanks for the great catch. But the problem is that even if |
Y'all this was litigated previously at #190. The JWT spec does NOT say to reject tokens with
If token issuers want clients to specify that a token should not be accepted before a certain timestamp (which puts additional constraints upon clients by implying that clients' clocks should keep relatively in sync with a central clock source and/or need to check it with leeway) then the issuer is supposed to set
I am currently getting bit by this issue a lot in a large enterprise microservices environment (where token issuer, token user, and token-accepting server which validates offline using RSA are three different machines) where clock drift is coming into play. Myself and 10+ other people have now wasted multiple days of person-time trying to figure out why tokens were being rejected, talking about how best to address it, and managing the workloads & deliverables of the people investigating & talking about this. Could this issue be re-opened and could the proper fix be to set the default value of Clients who understand the risks and want to engage in this extra-spec behavior should opt in by setting |
Just for fairness, I did some due diligence on the other libraries. Every other library I've found that does this has its own respective issue complaining about it. 😉 Libraries I found that do not check that Libraries that do (and their respective bug complaints):
Maybe this needs to be clarified in the spec since there's a pretty divided polity....... |
I'm going to be submitting an errata request for RFC 7519 about this. I'll be making my draft of that & centralizing the Github-side discussion here: Discussion: JWT tokens containing |
Lately, I've been encountering this error |
@Samk13 I've been chasing an issue with Django Allauth + DJ Rest Auth for the last couple of hours and re-syncing my Windows clock fixed this JWT iat error being raised inside of Allauth. So first, thank you haha, but second yes it appears I am also experiencing the same thing. |
PyJWT v2.8.0 verifies `iat` (issued-at timestamp) by default. There are several discussions on disabling this check, since it is not within spec. [Cognito's token verification guide](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-verifying-a-jwt.html#amazon-cognito-user-pools-using-tokens-manually-inspect) does not suggest verifying `iat`, unlike `exp`. Other discussions: jpadilla/pyjwt#814 jpadilla/pyjwt#939
See #939 |
We found an issue in one of our tests in the recent update of yours. Our package works with
pyjwt==2.5.0
but it breaks withpyjwt==2.6.0
. We will give more details on the issue once we explore it more and will try to provide a minimal example that reproduces the error. However, may I ask you to check if the latests changes could have broken backawards compatibility? We are particularly suspicious of #794. We think this because the error message we get:The token is not yet valid (iat)
.We are sorry we could not provide more details yet.
System Information
The text was updated successfully, but these errors were encountered: