Skip to content

feat(publisher): enforce playback token on the RTMP play path#32

Merged
ntt0601zcoder merged 2 commits into
mainfrom
feat/rtmp-playback-token
Jun 16, 2026
Merged

feat(publisher): enforce playback token on the RTMP play path#32
ntt0601zcoder merged 2 commits into
mainfrom
feat/rtmp-playback-token

Conversation

@ntt0601zcoder

Copy link
Copy Markdown
Owner

Summary

  • The RTMP play handler hardcoded an empty token into the media-auth chain, so any stream bound to a token-required policy was denied for every RTMP client with no way to authorize. Token policies effectively excluded RTMP while working on HLS/DASH/SRT/RTSP.
  • Carry the token on the play-URL query (rtmp://host/live/<code>?token=...), the same transport the SRT and RTSP play paths already use. The RTMP server forwards the session's raw query via PlayInfo.RawQuery (staying media-auth-agnostic); the publisher extracts the token with the shared sessions.TokenFromQuery helper.
  • User-Agent and Referer remain unset for RTMP, so those rules stay inert; IP / country / token now apply uniformly across protocols.

Changes

  • internal/ingestor/push/rtmp_server.go — add PlayInfo.RawQuery, populated from the session's raw query.
  • internal/publisher/serve_rtmp.go — extract the token from the play-URL query and pass it to the authorization chain.
  • internal/publisher/serve_rtmp_auth_test.go — table-driven auth tests (valid / missing / empty / garbage / expired / other-stream / wrong-secret / public / nil-authorizer).
  • docs/media-auth-policies.md — reference doc for the playback-policy model with a per-protocol enforcement matrix.

Testing

  • go build, go vet, gofmt clean
  • go test ./internal/publisher/ ./internal/ingestor/push/ pass

Note

Unit tests cover the authorization decision. Whether a given client places the query on the tcURL vs. the play stream name is client-dependent — verify end-to-end with a real encoder/player.

The RTMP play handler hardcoded an empty token into the media-auth chain,
so a stream bound to a token-required policy was denied for every RTMP
client with no way to authorize — token policies effectively excluded
RTMP while working on HLS/DASH/SRT/RTSP.

Carry the token on the play-URL query (rtmp://host/live/<code>?token=...),
the same transport the SRT and RTSP play paths already use. The RTMP
server forwards the session's raw query via PlayInfo.RawQuery (staying
media-auth-agnostic) and the publisher extracts the token with the shared
sessions.TokenFromQuery helper. User-Agent and Referer remain unset for
RTMP, so those rules stay inert; IP / country / token now apply uniformly.

Add table-driven auth tests for the RTMP play path and a reference doc
for the playback-policy model with a per-protocol enforcement matrix.
unparam flagged playAllowed's referer argument: RTMP / SRT / RTSP all
pass "" because none of those protocols carry a Referer (the
AllowedDomains gate runs only on the HTTP path). Remove the parameter
and update the call sites and tests; no behaviour change.
@ntt0601zcoder ntt0601zcoder merged commit 3543c62 into main Jun 16, 2026
4 checks passed
@ntt0601zcoder ntt0601zcoder deleted the feat/rtmp-playback-token branch June 17, 2026 02:43
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.

1 participant