Repository navigation
fix(security): custom claims cannot override the user ID in user tokens [SEC-2525] - #109
Open
oliverlaz wants to merge 5 commits into
Conversation
oliverlaz
marked this pull request as ready for review
November 25, 2026 12:39
mogita
reviewed
Nov 27, 2026
…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.
mogita
approved these changes
Nov 27, 2026
… [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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
iatandexp, anduser_idlast, so no custom claim can override the user ID.iatis set by the SDK unless the caller passes one.$expirationtakes precedence over a customexp; a customexpis kept when no expiration is given.Compatibility
A custom
user_idno longer changes the token's user.Changes
src/Auth/JWTGenerator.php:generateUserTokenbuilds the payload from the custom claims, then setsiat(if not given),expanduser_id, withuser_idthe last key.src/Client.php: docblock.tests/ClientTest.php: a test that other spellings ofuser_idin custom claims leave the user ID unchanged and thatuser_idis the last key.Testing
vendor/bin/phpunit tests --exclude-group integration(PHP 8.1),make lint.