Repository navigation
fix(api): let packaged TV apps open v2 sockets and read subtitle sidecars - #3327
Conversation
Packaged TV web apps (webOS, Tizen) load their pages from the device, so their WebSocket handshakes carry an Origin of "null", "file://" or an app scheme. The v2 socket origin check refused all of these with 403, so the events, playback-control and Watch Together sockets never opened on a TV. Treat an opaque or non-http(s) Origin like a missing one. The single-use ticket in the handshake protocols is what authorizes the socket, and a cross-site page cannot read a ticket mint answer. http(s) origins keep the exact public, request and overlay origin match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Suggested fix: Move or repeat the handshake table under Evidence and add the surface and build/commit. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
This should be ready, I'm making Moonfin for webOS compatible with Silo and this change blocks any app on those tv's not just Moonfin. |
Packaged TV web apps (webOS, Tizen) fetch subtitle sidecars from a page with an opaque Origin. Only the embedded-extract branch of the subtitle handler set Access-Control-Allow-Origin, so the browser discarded a 200 for an external or downloaded sidecar and the subtitle never rendered. Set the header once at the top of the handler so every branch, including errors and HEAD, carries it. The session token rides in the URL, not a cookie, so the wildcard grants nothing a cross-site page could use. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
|
Had to make an edit for subtitles. |
|
Evidence is incomplete for these visible changes:
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
Quick104
left a comment
There was a problem hiding this comment.
Two low-severity findings. Neither affects the socket authorization argument, which holds up: all four v2 sockets consume and recheck a ticket from Sec-WebSocket-Protocol, and the native API sends no CORS headers and reads no cookies, so a hostile page has no ticket to offer.
1. The published v2 contract still describes the old Origin rule (low). socketOriginHeaderDoc in internal/apiv2/admin_logs_socket.go documents the Origin header on all four socket operations: "Browser origin must match the configured public origin, the request origin, or a connected network access overlay origin." After this PR, null and non-web scheme origins are accepted, so contracts/api/v2/openapi.json and web/src/api/v2/schema.ts disagree with the code and with the updated prose docs. A third-party TV client reading the contract would conclude its packaged app is refused. Repair: reword the string and regenerate both artifacts. I'm fixing this in a commit on this branch, so there's no need to change it yourself. That commit also empties the three #3434 entries in contracts/api/v2/breaking-approvals.json. They now match nothing on main, so verify-apiv2-contract fails on any spec change until they're removed.
I merged main into the branch first (99721650d), because #3331 changed streamEmbeddedSubtitle. It merged cleanly.
🤖 Claude Code (claude-opus-5-5)
…itle answer The v2 contract's Origin description on the four socket operations still said every browser origin must match, while the handler now accepts opaque and non-web scheme origins. Reword it and regenerate the OpenAPI artifact and web types. Empty the three Silo-Server#3434 breaking-change approvals, which match nothing once that change is on main and fail the contract check for any later spec change. Set Access-Control-Allow-Origin at the top of the exported HandleSubtitle instead of handleSubtitle, so a malformed timestamp_offset 400 is readable from a packaged app too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
Review summaryReviewed head: Fit: 9/10 · Readiness: 8/10 — conditional (assuming CI is green) Fit: the change lets third-party packaged TV clients use the native realtime sockets without a new setting, and makes the change once, in the shared check. The security argument holds. All four v2 sockets (events, playback control, Watch Together, admin logs) authorize only with a single-use ticket offered in Readiness: the socket and subtitle tests this PR adds fail on main ( Addressed
Left for maintainers
Checks
🤖 Claude Code (claude-opus-5-5) |
Problem
Related issue: N/A
Validation tasks: unblocks #1206 C1
Packaged TV web apps can't open any Silo v2 WebSocket. webOS and Tizen apps load their pages from the device, not from Silo, so the browser sends an
Originofnull,file://or an app scheme. The app can't change it.socketOriginAllowedrefuses every one of those with403 origin refused, so the events, playback-control and Watch Together sockets never open on a TV. Moonfin Smart-TV hits this today.This change treats an opaque (
null) or non-http(s)scheme://Originthe same as a missing one, which native clients already send. The socket ticket still decides.Subtitles from external and downloaded sidecars don't render on a TV either. handleSubtitle sets Access-Control-Allow-Origin: * only on the embedded-extract branch, so the 200 for an external or downloaded sidecar has no CORS header. The packaged app fetches it with an opaque Origin, and the browser discards the answer before the app can read it. Found on webOS: the request shows as failed with no response headers, while the server logs getPlaybackSubtitle 200.
Approach
The Origin check guards against cross-site WebSocket hijacking, where a hostile page opens a socket that the browser authenticates for it. These sockets don't take ambient credentials. They take a single-use ticket offered in
Sec-WebSocket-Protocol, minted by an authenticatedPOST .../ws-ticket. /api/v2 sends no CORS headers on JSON routes, including the ticket mint, so a hostile page can't read a mint answer and has no ticket to offer, whatever Origin it sends. A sandboxed iframe that sendsnullis in the same position as an originless native client.httpandhttpsorigins keep the exact match against the public origin, the request's own origin and connected overlay origins, so a foreign web page (including one onlocalhost) is still refused. A value withoutscheme://, such as a barehost:port(whichurl.Parsereads as a scheme), is still refused. The shared check also covers the admin-logs socket. TV apps don't use it, but it takes the same ticket, so splitting the rule wasn't worth it. The frozen v1checkWebSocketOriginis unchanged, so a packaged app still can't open v1 sockets. On Silo, Smart-TV opens only/api/v2/events/ws. Its Xbox build serves the page from an ordinaryhttp://origin, which stays refused, so it will open that socket from native code instead, with noOrigin.An admin setting listing extra allowed origins was the other option. I didn't take it because every admin running TV clients would have to know to set it, and it guards nothing the ticket doesn't already guard.
docs/realtime-api.mdanddocs/architecture/native-raw-handshakes.mdnow describe the rule. TheOriginheader description on the four v2 socket operations in the OpenAPI contract (and the generated web types) says the same. The three#3434breaking-change approvals are removed, since they match nothing once that change is on main and fail the contract check for any later spec change. Native Apple and Android clients send noOriginand need no change. jellycompat has no equivalent check to match.The exported HandleSubtitle now sets Access-Control-Allow-Origin: * once, before anything else, so every answer carries it (external, embedded, downloaded, HEAD, and errors, including a malformed
timestamp_offset400), not just the embedded extract. A sidecar URL authorizes itself with the session ID and token in its query, not a cookie, so the wildcard lets a page read only a URL it already holds. The embedded branch and the font route already answer with *.Validation
go test ./internal/api/handlers/: pass. The origin table now coversnull,file://, an app scheme, a foreignlocalhostorigin, and schemeless and barehost:portvalues.go build ./...,go vet ./internal/api/...,gofmt,make lint-changedandmake verify-local-paths: pass.Test server on
main(8b526b17f), before and after this commit. Each row is one handshake to/api/v2/events/wswith a fresh ticket:TestSubtitleExternalSRTServesOriginalOrConvertedRepresentation now asserts Access-Control-Allow-Origin: * on the external sidecar. It fails without the fix and passes with it.
go test ./internal/api/handlers/, go vet, gofmt and make lint-changed pass on both commits.
Not run: the rest of the full gate (web,
make test-go, contract verifiers). Nothing outsideinternal/api/handlersand two docs changed. Not checked on TV hardware. Packaged webOS and Tizen apps loadindex.htmlfrom afile://document. Public reports showOrigin: nullfrom webOS andOrigin: file://from Tizen; which one appears depends on the web engine version. Both are accepted.Evidence
nullfile://app://com.example.tvhttp://localhost:8085(foreign)https://evil.testevil.test:443nullwith an invalid ticketRisks
Security: an opaque or non-web
Originno longer stops a handshake before the ticket check. This is safe only while every v2 socket authenticates with a ticket from the handshake protocols and never with a cookie. A future socket that accepts a cookie would need its own Origin rule. Browser-extension pages (chrome-extension://,moz-extension://) also pass the Origin check now. Like any other caller, they still need a ticket minted with the user's credentials.A page that somehow holds a sidecar URL, with its session ID and token, can now read the subtitle across origins. That URL is already a bearer credential for the same bytes, the same as a stream URL.
Checklist
AI Disclosure
/code-reviewon the full diff, looking for ways the new rule admits a hostile caller. It confirmed that/api/v2sends no CORS headers and that every v2 socket requires the ticket. It found that a barehost:portOrigin parsed as an app scheme and was accepted. That's fixed and has test rows now. It also raised extension origins, the admin-logs socket and v1 sockets; the Approach and Risks sections cover those.🤖 Generated with Claude Code
Note
Accept opaque and non-web Origins on v2 sockets and set wildcard CORS on subtitle responses
null) and non-HTTP(S) Origins inscheme://form, matching how packaged TV apps connect with ticket auth. Matching HTTP(S) Origins and absent Origins still pass; malformed Origins stay rejected.Access-Control-Allow-Originassignment to the start ofHandleSubtitlein stream_subtitle_offset.go, so all subtitle responses include the header, including error responses. Removes the old assignment in stream.go.events_socket_v2.goif stricter scheme checking is needed.HandleSubtitlenow always sendsAccess-Control-Allow-Origin: *, including error paths.Macroscope summarized e1a77f2.