Skip to content

fix(security): scope and expire SRT ingest tokens [SEC-2523] - #153

Merged
oliverlaz merged 5 commits into
mainfrom
oliverlazoroski/sec-2523-sec-10-permanent-unscoped-user-jwts
Nov 27, 2026
Merged

oliverlaz merged 5 commits into
mainfrom
oliverlazoroski/sec-2523-sec-10-permanent-unscoped-user-jwts

Conversation

@oliverlaz

@oliverlaz oliverlaz commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Submit a pull request

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

Ticket

https://linear.app/stream/issue/SEC-2523/sec-10-permanent-unscoped-user-jwts-embedded-in-srt-ingest-urls

Summary

The SRT credentials helper embedded a permanent, account-wide user token in the URL handed to OBS/encoders. The SRT stream id travels in the SRT handshake in cleartext, and a leaked encoder URL gave permanent access to that user's account.

The helper now mints a token that:

  • carries scoped_call_cid: "<type>:<id>": the backend (chat v241.21.0, CHA-6984) accepts it only for joining that call and reading app settings, and refuses it everywhere else, including the websocket. call_cids was deliberately not used: it grants the holder a role in those calls instead of restricting the token.
  • expires after 24 hours by default, with a caller override.

It also returns when the token expires, rejects a stream id over the 512-byte SRT limit with a clear error (encoders refuse longer ones), and redacts the address when the credentials are printed.

Why 24 hours, not shorter

The ingest uses this token as a normal user token for coordinator JoinCall, and calls it again on every SFU rejoin/migration. SFU tokens last 6h and the SFU forces a rejoin when one expires, so the user token is re-presented at least every 6 hours during a stream. If it has expired by then, the stream drops. The lifetime must therefore cover the wait until the encoder starts plus the whole stream.

Behaviour change

The API is backward compatible (only additions). An SRT URL generated once and left in an always-on encoder now stops working after 24 hours unless a longer lifetime is requested.

Backend dependency

scoped_call_cid is enforced from chat v241.21.0. Older backends ignore the unknown claim, so the token keeps working there, just without the call restriction.

API

  • New overload call.createSRTCredentials(userID, Duration validity); the existing one uses Call.DEFAULT_SRT_TOKEN_VALIDITY (24h).
  • New TokenBuilder.createScopedCallToken(userId, callCID, Instant expiresAt).
  • SRTCredentials gains Instant expiresAt and a toString() that redacts the address.

Testing

  • New SRTCredentialsTest and TokenBuilderTest cases (scope claim, lifetime, invalid lifetime, 512-byte limit, redaction).
  • ./gradlew spotlessCheck build passes locally on JDK 17.

Note

High Risk
Changes how SRT ingest authentication tokens are minted (scoped JWTs with expiration), which is security-critical and alters long-lived encoder URL behaviour.

Overview
SRT ingest URLs no longer embed permanent, full-account JWTs. createSRTCredentials now builds addresses using a call-scoped, expiring token (default 24h via DEFAULT_SRT_TOKEN_VALIDITY), with a new overload createSRTCredentials(userID, Duration validity) (minimum 1 second).

TokenBuilder.createScopedCallToken mints JWTs with scoped_call_cid (type:id) and an explicit expiresAt, restricting use to that call instead of a generic createToken(userID).

SRTCredentials gains expiresAt so callers know when the embedded token stops working. Behaviour change: always-on encoders using a one-time generated URL will need refresh or a longer validity after the default lifetime.

Tests cover scoped claims, custom/default expiry, and invalid validity; TokenBuilderTest covers the new token API.

Reviewed by Cursor Bugbot for commit f8ebce8. Bugbot is set up for automated code reviews on this repo. Configure here.

The SRT credentials helper embedded a permanent user token with full
account access in the encoder URL. It now mints a token that carries
scoped_call_cid (the backend lets it only join that call) and expires
after 24 hours by default. Callers can set another lifetime, the result
reports when the token expires, the helper rejects a stream id over the
512-byte SRT limit, and printing the credentials redacts the address.

The ingest re-presents the token on every SFU rejoin (at least every 6h),
so the lifetime must cover the whole stream. An SRT URL left in an
always-on encoder now stops working after 24 hours unless a longer
lifetime is requested.
@oliverlaz
oliverlaz requested review from mogita and vagruchi November 25, 2026 11:37
@oliverlaz
oliverlaz marked this pull request as ready for review November 25, 2026 12:39
…on [SEC-2523]

Per review on stream-node#417, the SDK no longer checks the SRT stream id
length and no longer redacts the address when the credentials are printed.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 90664b0. Configure here.

@oliverlaz
oliverlaz merged commit 1272aac into main Nov 27, 2026
11 checks passed
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