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

Uncaught ImmatureSignatureError: The token is not yet valid (iat) #307

Closed
corneliusroemer opened this issue Sep 1, 2023 · 6 comments · Fixed by #394
Closed

Uncaught ImmatureSignatureError: The token is not yet valid (iat) #307

corneliusroemer opened this issue Sep 1, 2023 · 6 comments · Fixed by #394
Labels
bug Something isn't working

Comments

@corneliusroemer
Copy link
Member

corneliusroemer commented Sep 1, 2023

Current Behavior

When I run nextstrain login I get an uncaught error nextstrain.cli.aws.cognito.TokenError: ImmatureSignatureError: The token is not yet valid (iat)

Expected behavior

Error is caught and wrapped into something useful for the enduser

How to reproduce

  1. Screw up your local system time
  2. Try nextstrain login

Example stack trace:

$ nextstrain login
Logging into Nextstrain.org…

Username: XXXXXX
Password: 

Traceback (most recent call last):
  File "nextstrain.cli.aws.cognito", line 249, in _verify_token
  File "jwt.api_jwt", line 210, in decode
  File "jwt.api_jwt", line 162, in decode_complete
  File "jwt.api_jwt", line 242, in _validate_claims
  File "jwt.api_jwt", line 278, in _validate_iat
jwt.exceptions.ImmatureSignatureError: The token is not yet valid (iat)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "runpy", line 196, in _run_module_as_main
  File "runpy", line 86, in _run_code
  File "nextstrain.cli.__main__", line 55, in <module>
  File "nextstrain.cli.__main__", line 19, in main
  File "nextstrain.cli", line 36, in run
  File "nextstrain.cli.command.login", line 103, in run
  File "nextstrain.cli.authn", line 69, in login
  File "nextstrain.cli.aws.cognito", line 167, in authenticate
  File "nextstrain.cli.aws.cognito", line 232, in verify_tokens
  File "nextstrain.cli.aws.cognito", line 261, in _verify_token
nextstrain.cli.aws.cognito.TokenError: ImmatureSignatureError: The token is not yet valid (iat)

Your environment: if running Nextstrain locally

  • Operating system: macOS 13.5.1, ARM
  • Version (e.g. auspice 2.7.0): nextstrain cli 7.2.0

Workaround

macOS: run sudo sntp -sS time.apple.com to sync my clock and that fixed things. My time was apparently 2 seconds off.

+2.158983 +/- 0.022257 time.apple.com 17.253.14.123

Possible solutions

  1. Add some more leeway for clock skew.
  2. Catch the error and raise another error with suggestions of how to fix.
  3. Catch the error and print a warning. Continue by trying again with Issued At verification disabled ("verify_iat": False).
  4. Disable the verification directly ("verify_iat": False) (This has been proposed as default behavior in pyjwt)

Links

@corneliusroemer corneliusroemer added the bug Something isn't working label Sep 1, 2023
@corneliusroemer
Copy link
Member Author

Maybe relevant: jpadilla/pyjwt#814

@corneliusroemer
Copy link
Member Author

Maybe we could increase the leeway for clock skew? In my case it appears to have been "just" 2 seconds. Not sure whether the we can increase leeway though. https://pyjwt.readthedocs.io/en/latest/usage.html#not-before-time-claim-nbf

@tsibley
Copy link
Member

tsibley commented Sep 1, 2023

It would certainly be friendlier in these cases to catch ImmatureSignatureError and issue a nice error message with suggestions of how to fix. And maybe adding some more leeway for clock skew.

@tsibley tsibley changed the title Uncaught error: nextstrain.cli.aws.cognito.TokenError: ImmatureSignatureError: The token is not yet valid (iat) Uncaught ImmatureSignatureError: The token is not yet valid (iat) Sep 1, 2023
@victorlin
Copy link
Member

How catching the error with a warning and trying again with "verify_iat": False? Example:

$ nextstrain login
Logging into https://nextstrain.org…

...
WARNING: Your computer clock time is out of sync. Some things may not work as expected.

Logged into https://nextstrain.org as victorlin.

$ nextstrain remote download nextstrain.org/zika ~/tmp
WARNING: Your computer clock time is out of sync. Some things may not work as expected.
Downloading https://nextstrain.org/zika as /Users/vlin/tmp/zika.json

@jameshadfield
Copy link
Member

Bumping this as it's happened twice now with LIMC collaborators. On a related slack thread there's a few votes to stop our CLI rejecting iat values from the future. @tsibley would you support a PR changing to "verify_iat": False, either outright or as Victor suggests?

@tsibley
Copy link
Member

tsibley commented Aug 29, 2024

Yes, I think it'd be fine to set "verify_iat": False. Besides disabling the iat <= (now + leeway) check, it also disables the check that iat is an integer (via int(iat) not throwing an exception). I think that side-effect is fine as we don't rely on int(iat) anywhere in Nextstrain CLI AFAIK.

jameshadfield added a commit that referenced this issue Aug 29, 2024
Client clock skew can lead to invalid JWTs
resulting the the following error during login:

```
nextstrain.cli.aws.cognito.TokenError:
ImmatureSignatureError: The token is not yet valid (iat)
````

See <#307>
and the (internal) Slack thread
<https://bedfordlab.slack.com/archives/C01LCTT7JNN/p1719286802460679>
for discussion about whether iat timestamps ahead of the current
clock are actually invalid JWTs.
jameshadfield added a commit that referenced this issue Aug 29, 2024
Client clock skew can lead to invalid JWTs
resulting the the following error during login:

```
nextstrain.cli.aws.cognito.TokenError:
ImmatureSignatureError: The token is not yet valid (iat)
````

See <#307>
and the (internal) Slack thread
<https://bedfordlab.slack.com/archives/C01LCTT7JNN/p1719286802460679>
for discussion about whether iat timestamps ahead of the current
clock are actually invalid JWTs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants