Skip to content

fix(playback): send CORS headers on v2 HLS playlists and segments - #4059

Merged
Quick104 merged 3 commits into
Silo-Server:mainfrom
blurbery:fix/hls-delivery-cors
Nov 13, 2026
Merged

Quick104 merged 3 commits into
Silo-Server:mainfrom
blurbery:fix/hls-delivery-cors

Conversation

@blurbery

@blurbery blurbery commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #4029
Validation tasks: none
Other clients: Apple N/A (no Google Cast sender yet; Silo-Server/silo-apple#702 tracks one); Android N/A (the Cast sender needs no change); Roku N/A (not a Cast receiver); Web N/A (the web player loads media from the server's own origin)

A Google Cast receiver plays HLS from a script on Google's origin (https://www.gstatic.com). It can only use a playlist or segment that the server marks as readable cross-origin. The native transcode routes (/api/v2/playback/transcode/{session_id}/master.m3u8 and /segment/{name}) send no Access-Control-Allow-Origin. So even with a working credential, the receiver fetches the playlist, can't read it, and stops before it asks for a segment. Subtitle sidecars already send the wildcard.

This change makes the playlist and segment answers readable from any origin. It's half of #4029. The other half, letting the plan URL's st stand in for the credential the receiver can't send, is #4060.

Approach

  • RawOperation gets a CrossOrigin option. RegisterRaw applies it outside the authorisation gate, so 401, 403 and 429 answers carry the headers too. The receiver then sees the real status instead of an opaque CORS failure.
  • With the option on, every answer has Access-Control-Allow-Origin: *, Access-Control-Allow-Headers: Range, and the Access-Control-Expose-Headers list the media proxy already sends.
  • Credentials are never allowed. These routes authorise with a header or a URL token, never a cookie, so a wildcard gives a cross-site page nothing it could use. HandleSubtitle relies on the same reasoning.
  • Only the two transcode routes opt in. /stream/{session_id}, subtitle sidecars and the JSON API are unchanged.
  • There's no OPTIONS handling, and raw v2 routes don't register OPTIONS. The reporter's Cast receiver sent no preflight, and Chromium sent none in my test for a GET with a single-range Range.
  • docs/architecture/api-contract.md (Browser origins) and docs/playback-api.md (Delivery) now describe this.

Validation

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-4059/

I captured this on a throwaway local server with a synthetic H.264 + E-AC-3 5.1 MKV. The playback start had a Cast-shaped profile: HLS only, and no header_authenticated_media_v1. Every request sent Origin: https://www.gstatic.com.

  • Before (main 0387303): no playlist or segment answer had a CORS header. A cross-origin fetch() in Chromium failed with "No 'Access-Control-Allow-Origin' header".
  • After (c621773): every answer carries the headers, refusals included, and the same page can read the response.
  • With fix(playback): accept the plan URL's st on v2 media requests #4060 as well: hls.js on another origin plays the plan URL as returned.

Risks

A page on any origin can now read these responses, but only if it already holds the account token or the session's signed st. Without one of those it gets nothing. Preflighted requests still fail, as noted above.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

AI-assisted with Claude Opus. I directed the task and designed the work.

  • Harness: Claude Code (desktop app)
  • Tool(s): Claude Code built-in tools, its built-in Chromium browser pane, GitHub CLI, curl, ffmpeg
  • Model(s): claude-opus-5-5
  • Involvement: AI-assisted
  • Adversarial review: n/a

Note

Add wildcard CORS headers to v2 HLS playlist and segment responses

  • Adds a CrossOrigin option to RawOperation and a mediaCrossOrigin middleware in raw_registration.go. The middleware sets Access-Control-Allow-Origin: *, allows the Range request header, and exposes range/validator headers. It does not set credentialed CORS or handle OPTIONS preflight.
  • registerPlaybackDelivery in playback_delivery.go enables the option for routes with the HLS transcode path prefix. Because the middleware wraps the authorization chain, authorization refusals also carry the headers.
  • Adds TestPlaybackHLSDeliveryAnswersCrossOrigin in playback_delivery_test.go covering manifest, ranged segment, and refused requests, plus absence of CORS on original-media and JSON paths.
  • Updates the CORS contract in api-contract.md and playback-api.md.
  • Behavioral Change: HLS manifest and segment responses, including auth refusals, now include wildcard CORS headers; non-HLS delivery paths are unchanged.

Macroscope summarized c621773.

A Google Cast receiver plays HLS from a script on Google's origin, so it
could fetch the v2 transcode playlist but not read it, and stopped before
requesting a segment. Subtitle sidecars already answered with a wildcard.

RawOperation gains CrossOrigin. RegisterRaw then sets
Access-Control-Allow-Origin: *, allows Range and exposes the range and
validator headers the media proxy exposes, outside the authorization gate,
so refusals are readable too. No credentials are allowed and no OPTIONS
preflight is answered; a single-range GET needs none. Only the manifest and
segment operations opt in.

Related issue: Silo-Server#4029
Keep the HLS protocol literal in one constant now that the cross-origin
opt-in compares against it, and describe the missing OPTIONS preflight by
what Cast receivers have been seen to send.
The protocol constant changed the playlist and segment table rows, and
goconst then flagged the unchanged "getPlaybackManifest" literal on the
edited row. Leave the rows as they were and opt the transcode routes in by
their path prefix instead.
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The API now applies wildcard CORS headers to opted-in raw operations. Playback registration opts HLS transcode routes into this middleware. Tests and documentation cover response headers, refusals, range requests, and preflight behavior.

Changes: HLS Cross-Origin Delivery

Layer / File(s) Summary
Raw operation CORS middleware
internal/apiv2/raw_registration.go
RawOperation.CrossOrigin enables middleware that sets wildcard origin, allows Range, and exposes media response headers. The middleware does not handle OPTIONS preflights.
HLS route opt-in and validation
internal/apiv2/playback_delivery.go, internal/apiv2/playback_delivery_test.go, docs/architecture/api-contract.md, docs/playback-api.md
Playback registration enables the option for paths with the transcode prefix. Tests cover HLS manifest and segment responses, refusal responses, ranged delivery, and unaffected stream and library routes. Documentation describes the CORS behavior and limits.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Possibly related issues

Suggested labels: go, api-v2

Suggested reviewers: quick104, rhainland

Merge Risk: Minimal · up to c6217

This change lets a Cast receiver on another origin read HLS playlist and segment responses. It is opt-in and limited to two routes, and authorization is unchanged. No merge-blocking risk was found.

Security architecture risk: Low · up to c6217

The change deliberately allows other websites to read HLS responses, but protected media still requires an explicitly supplied credential. Existing authentication and viewer checks remain in place, and cookie-authenticated cross-origin reads are not enabled. No authorization bypass was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The introduced exposure is browser-readable HLS media and refusal responses from any origin, limited to the two opted-in routes. Reading protected media still depends on credentials and the existing authorization decisions; the wildcard does not independently grant account or session authority.

Security Findings and Attack Paths

  • inferred — No ambient-credential media-read attack was established. An untrusted page without a supplied credential reaches the generic authentication refusal before session-specific playback logic. A page that already possesses a valid credential gains browser readability, which is the intended contract expansion.

Trust Boundaries and Controls

  • observed — Existing authentication continues to validate token type, active session ownership, remote-playback restrictions, and current role before forwarding JWT-authenticated requests. API keys retain scope checks. These controls are unchanged by the full PR comparison.

Resilience and Maintainability Implications

  • observed — Credential-store failures remain fail-closed with retryable 503 responses rather than granting access. The CORS wrapper changes their browser visibility, not the authentication decision.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(playback): send CORS headers on v2 HLS playlists and segments" matches the main change. The diff adds a CrossOrigin option to RawOperation and enables it for the HLS transcode routes, s…
Description check Passed The description explains the problem (a Google Cast receiver cannot read HLS playlists and segments without Access-Control-Allow-Origin), the approach (RawOperation CrossOrigin option, applied to the …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(playback): send CORS headers on v2 HLS playlists and segments" matches the main change. The diff adds a CrossOrigin option to RawOperation and enables it for the HLS transcode routes, so the response headers are sent on those playlists and segments. The title is short and specific, and it does not describe anything outside the changeset.

Full details: Description check

Explanation

The description explains the problem (a Google Cast receiver cannot read HLS playlists and segments without Access-Control-Allow-Origin), the approach (RawOperation CrossOrigin option, applied to the transcode routes outside the authorization gate), validation, evidence, and risks. It is clearly related to the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0974b12a-d7c7-4fcc-a567-61a1b214784c
Commits

Reviewing files that changed from the base of the PR and between 0387303 and c621773.

Files selected for processing: 5

  • docs/architecture/api-contract.md
  • docs/playback-api.md
  • internal/apiv2/playback_delivery.go
  • internal/apiv2/playback_delivery_test.go
  • internal/apiv2/raw_registration.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

@silo-kody

silo-kody Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added bug Something isn't working impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish labels Nov 13, 2026
Comment thread internal/apiv2/raw_registration.go Resolved
@blurbery
blurbery marked this pull request as ready for review November 13, 2026 07:32
@coderabbitai coderabbitai Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase go Pull requests that update go code labels Nov 13, 2026

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Claude Code (claude-opus-5-5)

One low-severity finding, on the docs. The code does what the description says. I traced the middleware order, the gate-denial rendering, the delivery error writer and the node relay, and the headers survive on each. I'm not pushing anything to this branch.

Comment on lines +1093 to +1095
tested policies. The native HLS manifest and segment routes send the same uncredentialed
wildcard on every answer, authorization refusals included, because a Google Cast receiver plays
them from a script on Google's origin; a raw operation opts in with `RawOperation.CrossOrigin`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Low: the docs promise CORS on more answers than get it.

This paragraph, the Delivery paragraph in docs/playback-api.md, and the CrossOrigin comment in raw_registration.go all say every answer carries the headers, refusals included. That holds for everything the operation writes, including the class gate's 401, 403 and 429. A few refusals come earlier and carry no CORS: the 403 for an unknown X-Silo-Ingress-Token (netaccess.Middleware), the v2 router's malformed device-header check, and router 404 and 405 answers, which include any OPTIONS preflight. A Cast receiver sends neither of the first two headers, so it shouldn't hit them, but a reader of the contract would expect them covered.

The paragraph also calls this "the same" wildcard as the media proxy. The proxy also answers preflights and allows Authorization, the profile headers and the conditional headers, and these routes don't.

Suggested wording below. The same qualification ("once a request reaches the operation") fits the other two places.

Suggested change
tested policies. The native HLS manifest and segment routes send the same uncredentialed
wildcard on every answer, authorization refusals included, because a Google Cast receiver plays
them from a script on Google's origin; a raw operation opts in with `RawOperation.CrossOrigin`.
tested policies. The native HLS manifest and segment routes send the same uncredentialed
wildcard on every answer once a request reaches the operation, its authorization refusals
included, because a Google Cast receiver plays them from a script on Google's origin; a raw
operation opts in with `RawOperation.CrossOrigin`. Unlike the media proxy, these routes answer
no `OPTIONS` preflight, so only requests that need none can read them cross-origin.

@Quick104

Copy link
Copy Markdown
Contributor

🤖 Claude Code (claude-opus-5-5)

Review summary

Reviewed head: c621773

The defect is real on main. A playlist answer from /api/v2/playback/transcode/{session_id}/master.m3u8 comes back with no Access-Control-Allow-Origin. I ran this PR's new test against the base with the two header constants written out as literals, and it fails on the first assertion. On the head it passes. (As committed, the test doesn't build on the base because it uses the constants this PR adds.)

The wildcard is safe on these routes. They authorize only with an explicit credential: Authorization: Bearer or ?token= for the account, and the X-Profile-* headers for the viewer. No cookie, HTTP auth or client address counts. Without a credential, a page on another origin gets only the generic 401, which is answered before any session lookup. With one, it can already do everything the credential allows without CORS. The wildcard never comes with Access-Control-Allow-Credentials. The media proxy, jellycompat and subtitle sidecars already send a wildcard on the same reasoning.

What it fixes on its own. A cross-origin player that already holds a valid credential, such as a Cast receiver given a ?token= URL, can now read the playlist and segments. That's the second half of #4029, and the reporter's relay showed it was the missing piece once requests authenticated. It doesn't fix the shipping Android Cast flow: that sender passes the plan URL with only st, which still gets a 401 until something accepts st (#4060 proposes one way). Any credential design for Cast still needs these headers, so this PR can merge before that's decided. The two PRs merge together without conflicts.

Addressed findings: none. I posted one low-severity docs finding with suggested wording and left the branch as it is.

Remaining for maintainers

  • Whether to apply the docs wording in the review comment: refusals written before the request reaches the operation (unknown ingress token, malformed device header, router 404/405) carry no CORS.
  • No OPTIONS preflight, as the description says. The earlier thread on that is settled.
  • Subtitle sidecars set Access-Control-Allow-Origin only from their handler. Their gate refusals carry none, and they don't expose Retry-After. That's older than this PR, and sidecars could opt into CrossOrigin in a follow-up.

Validated features: I couldn't read the validation board, so this is unconfirmed. From the source: the change only adds response headers. Same-origin web playback and the native Apple, Android and Roku players don't read CORS headers, so I found no passed case this changes. Validation tasks: none looks right.

User manual: unaffected. The manual doesn't describe Cast or these headers.

Other clients: no client change needed. The Android Cast sender needs #4029's credential half, not this one, and the description's Other clients: line is accurate.

Review method: three read-only finder agents and a cross-provider review (gpt-6.1-sol) on this head. Its one finding is the docs comment above.

Fit: 9/10 · Readiness: 8/10 — conditional

  • Fit: it's a narrow fix that lets third-party players like Cast receivers use the native HLS routes. It follows the cross-origin policy the media proxy and subtitle sidecars already use, and it changes nothing for same-origin or native clients.
  • Readiness: the code is correct and a test catches the regression. Two things keep it from ready: the docs overstate which answers carry the headers, and no one has shown Cast playback end to end without fix(playback): accept the plan URL's st on v2 media requests #4060.

@Quick104
Quick104 merged commit b8f667d into Silo-Server:main Nov 13, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants