Repository navigation
fix(playback): send CORS headers on v2 HLS playlists and segments - #4059
Conversation
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.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Quick104
left a comment
There was a problem hiding this comment.
🤖 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.
| 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`. |
There was a problem hiding this comment.
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.
| 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. |
|
🤖 Claude Code (claude-opus-5-5) Review summaryReviewed head: c621773 The defect is real on main. A playlist answer from The wildcard is safe on these routes. They authorize only with an explicit credential: What it fixes on its own. A cross-origin player that already holds a valid credential, such as a Cast receiver given a Addressed findings: none. I posted one low-severity docs finding with suggested wording and left the branch as it is. Remaining for maintainers
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. 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 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
|
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.m3u8and/segment/{name}) send noAccess-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
ststand in for the credential the receiver can't send, is #4060.Approach
RawOperationgets aCrossOriginoption.RegisterRawapplies 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.Access-Control-Allow-Origin: *,Access-Control-Allow-Headers: Range, and theAccess-Control-Expose-Headerslist the media proxy already sends.HandleSubtitlerelies on the same reasoning./stream/{session_id}, subtitle sidecars and the JSON API are unchanged.OPTIONShandling, and raw v2 routes don't registerOPTIONS. The reporter's Cast receiver sent no preflight, and Chromium sent none in my test for a GET with a single-rangeRange.docs/architecture/api-contract.md(Browser origins) anddocs/playback-api.md(Delivery) now describe this.Validation
go test ./internal/apiv2/passes. The new delivery test fails without the change. It covers the playlist, a ranged segment, gate refusals, a handler error, and routes that must stay same-origin.go vet ./internal/apiv2/passes.make verify-apiv2-openapipasses, and the spec is unchanged.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 sentOrigin: https://www.gstatic.com.main0387303): no playlist or segment answer had a CORS header. A cross-originfetch()in Chromium failed with "No 'Access-Control-Allow-Origin' header".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
AI Disclosure
AI-assisted with Claude Opus. I directed the task and designed the work.
Note
Add wildcard CORS headers to v2 HLS playlist and segment responses
CrossOriginoption toRawOperationand amediaCrossOriginmiddleware in raw_registration.go. The middleware setsAccess-Control-Allow-Origin: *, allows theRangerequest header, and exposes range/validator headers. It does not set credentialed CORS or handleOPTIONSpreflight.registerPlaybackDeliveryin 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.TestPlaybackHLSDeliveryAnswersCrossOriginin playback_delivery_test.go covering manifest, ranged segment, and refused requests, plus absence of CORS on original-media and JSON paths.Macroscope summarized c621773.