Skip to content

fix(session): reject an access token that has no exp claim - #789

Open
gjtorikian wants to merge 1 commit into
mainfrom
fix/session-require-exp
Open

gjtorikian wants to merge 1 commit into
mainfrom
fix/session-require-exp

Conversation

@gjtorikian

Copy link
Copy Markdown
Contributor

Description

On main, the session verifier accepted an access token that had a correct signature and no exp claim. It also accepted an exp claim that was a string of digits, because PyJWT reads exp with int(). Now authenticate and refresh of Session and AsyncSession return an error response with the INVALID_JWT reason for these tokens. That is the result for a token with an incorrect signature. Each jwt.decode call of the verifier now has "require": ["exp"] in its options. A check after the call rejects an exp claim that is not a JSON number.

Behavior changes

Access token with a correct signature main This change
No exp claim authenticate and refresh return a success response INVALID_JWT
exp is a string that int() can read, for example "1900000000" authenticate and refresh return a success response until that time (plus jwt_leeway) INVALID_JWT
exp is true or false, and jwt_leeway is larger than the current Unix time authenticate and refresh return a success response INVALID_JWT
  • exp as JSON null gave INVALID_JWT on main. It gives INVALID_JWT now.
  • The results are the same for Session and AsyncSession, and for RS256 and ES256.
  • When refresh rejects the new access token, it keeps session_data. get_logout_url raises its usual ValueError for a token that authenticate rejects.

No change

  • A token with a numeric exp keeps its result. A token that is not expired authenticates as before, with an integer exp or an exp with a fraction. An expired token gives INVALID_JWT as before, and refresh keeps session_data.
  • The signature rules, the key selection, the JWKS behavior, the other claim checks and the leeway do not change.
  • Public names, parameters, return types and failure reasons do not change. The change adds no error type.

Tests

  • The new tests make RS256 tokens at test time and call authenticate and refresh of Session and AsyncSession.
  • A token with no exp, with exp as null, or with exp as a string of digits gives INVALID_JWT, and refresh keeps session_data.
  • Four tests stop the type check. They show that the PyJWT require option rejects a token with no exp claim.
  • Control tests show that a token with an integer exp or an exp with a fraction still authenticates and refreshes.
  • A table test of the type check includes a boolean exp and an array exp.
  • No test or fixture of main had a token with no exp claim and an expected success. Thus no fixture got an exp claim.

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

The session verifier accepted an access token with a correct signature
and no exp claim. It also accepted an exp claim that was a string of
digits. Now Session and AsyncSession give INVALID_JWT for these tokens.
Each jwt.decode call now has "require": ["exp"] in its options, and a
type check rejects an exp claim that is not a number. The result for a
numeric exp, the signature rules and the public API do not change.
@gjtorikian
gjtorikian requested a review from a team as a code owner December 4, 2026 06:29
@greptile-apps

greptile-apps Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Requires a numeric exp claim when Session and AsyncSession authenticate or refresh an access token.

  • Session authentication and refresh require a numeric token expiry.

Reviews (1) · Last reviewed commit: "fix(session): reject an access token tha..." · Reviewed by Greptile

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant