Repository navigation
fix(security): scope and expire SRT ingest tokens [SEC-2523] #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
oliverlaz
merged 5 commits into
main
from
oliverlazoroski/sec-2523-sec-10-permanent-unscoped-user-jwts
Nov 27, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e4ab1f1
fix(security): scope and expire SRT ingest tokens [SEC-2523]
oliverlaz 473a86f
fix(security): drop SRT stream id length check and credential redacti…
oliverlaz 90664b0
Merge branch 'main' into oliverlazoroski/sec-2523-sec-10-permanent-un…
oliverlaz 24cda2b
Merge branch 'main' into oliverlazoroski/sec-2523-sec-10-permanent-un…
oliverlaz f8ebce8
Merge branch 'main' into oliverlazoroski/sec-2523-sec-10-permanent-un…
oliverlaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/io/getstream/models/framework/SRTCredentials.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,18 @@ | ||
| package io.getstream.models.framework; | ||
|
|
||
| import java.time.Instant; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| /** | ||
| * SRT address an encoder (OBS, ffmpeg, ...) publishes to. The address contains a user token, so | ||
| * keep it secret. | ||
| */ | ||
| @Builder | ||
| @Getter | ||
| public class SRTCredentials { | ||
| String address; | ||
|
|
||
| /** When the token in the address expires. */ | ||
| Instant expiresAt; | ||
| } |
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
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
94 changes: 94 additions & 0 deletions
94
src/test/java/io/getstream/services/SRTCredentialsTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package io.getstream.services; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import io.getstream.exceptions.StreamException; | ||
| import io.getstream.models.framework.SRTCredentials; | ||
| import io.getstream.services.framework.TokenBuilder; | ||
| import io.jsonwebtoken.Claims; | ||
| import io.jsonwebtoken.Jwts; | ||
| import io.jsonwebtoken.security.Keys; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.time.Duration; | ||
| import java.util.regex.Pattern; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| public class SRTCredentialsTest { | ||
| private static final String API_KEY = "srt-test-key"; | ||
| private static final String SECRET = "a-test-secret-that-is-long-enough-for-hs256"; | ||
| private static final Pattern TOKEN = Pattern.compile("streamid=[^/]+/(.+)$"); | ||
|
|
||
| private static String template(String callType, String callID) { | ||
| return "srt://ingress.stream-io-video.com:10080?mode=caller&passphrase={passphrase}&streamid=" | ||
| + API_KEY | ||
| + "." | ||
| + callType | ||
| + "." | ||
| + callID | ||
| + "/{token}"; | ||
| } | ||
|
|
||
| private static SRTCredentials build(String callID, String userID, Duration validity) | ||
| throws StreamException { | ||
| return Call.buildSRTCredentials( | ||
| template("livestream", callID), | ||
| new TokenBuilder(SECRET), | ||
| userID, | ||
| "livestream:" + callID, | ||
| validity); | ||
| } | ||
|
|
||
| private static String tokenOf(SRTCredentials credentials) { | ||
| var matcher = TOKEN.matcher(credentials.getAddress()); | ||
| assertTrue(matcher.find()); | ||
| return matcher.group(1); | ||
| } | ||
|
|
||
| private static Claims claimsOf(String token) { | ||
| return Jwts.parser() | ||
| .verifyWith(Keys.hmacShaKeyFor(SECRET.getBytes(StandardCharsets.UTF_8))) | ||
| .build() | ||
| .parseSignedClaims(token) | ||
| .getPayload(); | ||
| } | ||
|
|
||
| @Test | ||
| void embedsCallScopedTokenThatExpiresAfterTheDefaultValidity() throws StreamException { | ||
| var credentials = build("my-call", "john", Call.DEFAULT_SRT_TOKEN_VALIDITY); | ||
| var token = tokenOf(credentials); | ||
| var claims = claimsOf(token); | ||
|
|
||
| assertEquals(Duration.ofHours(24), Call.DEFAULT_SRT_TOKEN_VALIDITY); | ||
| assertEquals("john", claims.get("user_id")); | ||
| assertEquals("livestream:my-call", claims.get("scoped_call_cid")); | ||
| assertNull(claims.get("call_cids")); | ||
| assertEquals(credentials.getExpiresAt(), claims.getExpiration().toInstant()); | ||
| var lifetime = | ||
| Duration.between(claims.getIssuedAt().toInstant(), claims.getExpiration().toInstant()); | ||
| assertTrue(lifetime.compareTo(Duration.ofHours(24)) >= 0, lifetime.toString()); | ||
| assertTrue(lifetime.compareTo(Duration.ofHours(24).plusSeconds(10)) <= 0, lifetime.toString()); | ||
| assertTrue(credentials.getAddress().contains("passphrase=" + token.split("\\.")[2] + "&")); | ||
| } | ||
|
|
||
| @Test | ||
| void acceptsCustomValidity() throws StreamException { | ||
| var claims = claimsOf(tokenOf(build("my-call", "john", Duration.ofHours(3)))); | ||
| var lifetime = | ||
| Duration.between(claims.getIssuedAt().toInstant(), claims.getExpiration().toInstant()); | ||
|
|
||
| assertTrue(lifetime.compareTo(Duration.ofHours(3)) >= 0, lifetime.toString()); | ||
| assertTrue(lifetime.compareTo(Duration.ofHours(3).plusSeconds(10)) <= 0, lifetime.toString()); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(longs = {0, -1, 999}) | ||
| void rejectsValidityUnderOneSecond(long millis) { | ||
| assertThrows( | ||
| IllegalArgumentException.class, () -> build("my-call", "john", Duration.ofMillis(millis))); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.