Skip to content

Reject session JWTs in M2M authenticateToken - #321

Draft
logan-twilio wants to merge 1 commit into
mainfrom
lgore/m2m-reject-session-jwt
Draft

logan-twilio wants to merge 1 commit into
mainfrom
lgore/m2m-reject-session-jwt

Conversation

@logan-twilio

Copy link
Copy Markdown
Contributor

Summary

M2M authenticateToken validates the JWT's signature, issuer, audience and
expiry locally, but never checked that the token is an M2M access token.
Session JWTs are signed with the same project keys and pass those checks, so a
session JWT could be accepted as an M2M token.

authenticateToken now rejects any token that contains the
https://stytch.com/session claim. Stytch never puts that claim on M2M tokens,
and it can't be set as a custom claim, so legitimate M2M tokens are unaffected.

Changes

  • authenticate_token and authenticate_token_async return None when the
    session claim is present, matching their other JWT failures.
  • Adds sync authenticate_token tests (previously only async was covered).
  • Version 15.3.0 → 15.3.1.

Testing

  • New test: a JWT signed with the project key carrying a valid scope claim and
    a https://stytch.com/session claim is rejected.
  • Existing/new test: a normal M2M token is still accepted.
  • Verified the new rejection test fails with the fix reverted.

Compatibility

Patch release. The only behavior change is that session JWTs passed to M2M
authenticateToken are now rejected. No valid M2M token is affected.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant