Skip to content

fix(security): reject reserved claims in user tokens [SEC-2525] - #109

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

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

Conversation

@oliverlaz

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

The backend treats a JWT as a server token when its user_id is empty; the server claim itself is ignored. User-token helpers let caller-supplied custom claims overwrite user_id (or, in Node, accepted an empty user_id), so a custom claim such as user_id: "" could mint a token with full API access. This matters when an app forwards untrusted input into custom claims.

Behavior (same across Go, Node and PHP; the Rust SDK already does this)

  • user_id comes only from the user ID argument and must be non-empty.
  • user_id or server in custom claims is rejected with an error.
  • An explicit expiration still wins over a custom exp; a custom exp/iat is kept when no expiration is given.
  • role, call_cids and channel_cids stay allowed in custom claims (documented usage relies on them).

Compatibility

Callers that put user_id or server in custom claims, or pass an empty user_id, now get an error instead of a token. Neither is a legitimate use.

Changes

  • src/Auth/JWTGenerator.php: generateUserToken throws StreamException for reserved claims.
  • src/Client.php: docblock for createUserToken.
  • tests/ClientTest.php: tests for reserved claims and exp precedence.

Testing

make lint and make test-unit on PHP 8.1 and 8.5.

@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.

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