Skip to content

🐛 add 10 seconds leeway for session token check on the nbf#175

Merged
lishanl merged 3 commits intomainfrom
fix/session-token-leeway
Dec 14, 2022
Merged

🐛 add 10 seconds leeway for session token check on the nbf#175
lishanl merged 3 commits intomainfrom
fix/session-token-leeway

Conversation

@lishanl
Copy link
Copy Markdown
Collaborator

@lishanl lishanl commented Dec 14, 2022

encountering the following ImmatureSignatureError from time to time when doing the end to end test with the PIM client.

webapp_1   |   File "/python/app/./middleware/session_token.py", line 47, in __call__
webapp_1   |     session = SessionToken.from_header(headers.get('Authorization'), self.api_key, self.secret)
webapp_1   |   File "/home/python/lib/python3.9/site-packages/spylib/session_token.py", line 81, in from_header
webapp_1   |     payload = decode(
webapp_1   |   File "/home/python/lib/python3.9/site-packages/jwt/api_jwt.py", line 119, in decode
webapp_1   |     decoded = self.decode_complete(jwt, key, algorithms, options, **kwargs)
webapp_1   |   File "/home/python/lib/python3.9/site-packages/jwt/api_jwt.py", line 106, in decode_complete
webapp_1   |     self._validate_claims(payload, merged_options, **kwargs)
webapp_1   |   File "/home/python/lib/python3.9/site-packages/jwt/api_jwt.py", line 139, in _validate_claims
webapp_1   |     self._validate_nbf(payload, now, leeway)
webapp_1   |   File "/home/python/lib/python3.9/site-packages/jwt/api_jwt.py", line 168, in _validate_nbf
webapp_1   |     raise ImmatureSignatureError("The token is not yet valid (nbf)")
webapp_1   | jwt.exceptions.ImmatureSignatureError: The token is not yet valid (nbf)

did a bit googling and found that's an existing issue others encountered as well
ref: Session_token Gives Me Error "The Token Is Not Yet Valid (Nbc)"
and the shopify python library has it fixed with the leeway that applies to nbf, exp, iat:
Accept 10 seconds clock skew to avoid ImmatureSignatureError

The solution is applied here as well.

@lishanl lishanl added the Type: Enhancement New feature or request label Dec 14, 2022
@lishanl lishanl self-assigned this Dec 14, 2022
@lishanl lishanl requested a review from hillairet as a code owner December 14, 2022 00:15
@lishanl lishanl requested a review from ponty33 December 14, 2022 00:15
@lishanl
Copy link
Copy Markdown
Collaborator Author

lishanl commented Dec 14, 2022

I have update the pyproject.toml to not upate the httpx and fastapi to the latest version because they both contain breaking changes. To be dealt with in another PR:
httpx==0.23.1, breaking change on url typing, likely to
fastapi==0.87.0, breaking change on testclient

Please refer to the 2 CI failures in the PR.

@lishanl lishanl merged commit a812105 into main Dec 14, 2022
@lishanl lishanl deleted the fix/session-token-leeway branch December 14, 2022 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants