Skip to content

fix(security): custom claims cannot override the user ID in user tokens [SEC-2525] - #109

Open
oliverlaz wants to merge 5 commits into
GetStream:masterfrom
oliverlaz:oliverlazoroski/sec-2525-sec-13-jwt-custom-claim-overwrite
Open

oliverlaz wants to merge 5 commits into
GetStream:masterfrom
oliverlaz:oliverlazoroski/sec-2525-sec-13-jwt-custom-claim-overwrite

Conversation

@oliverlaz

@oliverlaz oliverlaz commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Ticket

https://linear.app/stream/issue/SEC-2525/sec-13-jwt-custom-claim-overwrite-server-true-escalation-go-node-php

Why

A user token for one user must stay a token for that user. Custom claims could override user_id, so an app that forwards untrusted input into custom claims could mint a token for someone else.

Behavior

  • Custom claims are written first, then iat and exp, and user_id last, so no custom claim can override the user ID.
  • iat is set by the SDK unless the caller passes one. $expiration takes precedence over a custom exp; a custom exp is kept when no expiration is given.
  • Custom claims are otherwise unchanged.

Compatibility

A custom user_id no longer changes the token's user.

Changes

  • src/Auth/JWTGenerator.php: generateUserToken builds the payload from the custom claims, then sets iat (if not given), exp and user_id, with user_id the last key.
  • src/Client.php: docblock.
  • tests/ClientTest.php: a test that other spellings of user_id in custom claims leave the user ID unchanged and that user_id is the last key.

Testing

vendor/bin/phpunit tests --exclude-group integration (PHP 8.1), make lint.

@oliverlaz
oliverlaz requested review from itsmeadi and mogita November 25, 2026 11:36
@oliverlaz
oliverlaz marked this pull request as ready for review November 25, 2026 12:39
Comment thread src/Auth/JWTGenerator.php Resolved
…525]

The backend decodes JWT claims with Go's encoding/json, which matches
names case-insensitively with Unicode simple folding and lets the last
matching key win, so a custom claim such as USER_ID or uſer_id could
replace or blank the user_id (a blank one is a server token).

Reject custom claims that are another spelling of a claim the backend
reads, reserve egress, and require a custom iat to be a positive whole
Unix timestamp that is not in the future (a missing iat skips per-user
token revocation).

Also put user_id last in the payload.
… [SEC-2525]

Custom claims are written first, then the SDK's iat (when not given) and
exp, and user_id last. This replaces the reserved-claim checks.
@oliverlaz oliverlaz changed the title fix(security): reject reserved claims in user tokens [SEC-2525] fix(security): custom claims cannot override the user ID in user tokens [SEC-2525] Nov 30, 2026
@oliverlaz
oliverlaz requested a review from mogita November 30, 2026 08:25

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants