fix(player)!: read a trusted package and a bundle only from the origin their address names

Merged
AL
3h ago
+211-13

Summary

Closes #340. trusted and libraries vouch for an address, and the player followed redirects, so a trusted package or a library bundle whose address redirected to another origin played with that origin's code. Now only a redirect within the address's own origin is followed for them.

Changes

  • probeSource takes code: for a trusted package (src with trusted) and a bundle (a .h5p in libraries), a response that Response.redirected and Response.url say came from another origin is refused (network), naming both origins.
  • A probe answered from the address's own origin marks the descriptor sameOrigin, and every later read holds to it (holdToOrigin): the Service Worker's range reads, the probe's size request, and the Jobs worker's download. The mark comes from the address, not the load's mode, so two loads of one package, trusted and untrusted, agree.
  • An untrusted package found through a redirect elsewhere is unmarked and follows redirects as before: its code does not run.
  • The pack's parts are unchanged: each is checked against the index's hash.
  • Test-only: a /redirect/<fixture>?to=<loopback origin> route on the player's dev server.
  • Docs: the rule in design/security.md; docs/api.md (trusted, libraries), docs/untrusted.md (a table row), the player README's 1.x note.

Breaking, for the release notes (player 2.0): a trusted package, or a library bundle, whose address redirects to another origin is refused. Its address on the origin that serves it plays.

Verification

  • tests/browser/redirects.test.ts, with real redirects to the test server's loopback address: same-origin redirects play, trusted and as a bundle; a trusted package and a bundle redirected to another origin are refused with the message; an untrusted one plays through the redirect with the bundle's code. Chromium, Firefox and WebKit: 4 passed each.

  • tests/unit/source-probe.test.ts: the probe's refusal and its follow for data; a read refused when the address starts redirecting elsewhere during a load; an unmarked address unaffected. 11 passed.

  • Player suite in Chromium: 640 passed, plus 1 failure in playback.test.ts ("applies the H5P core styles", 'normal' for '24px') that passed on a re-run (31 of 31). It is in the same file as this morning's one-off CI failure on #339.

  • pnpm typecheck, pnpm lint, pnpm comments: pass.

  • Tests added or updated where behavior changed

  • Documentation updated where public behavior or deployment changed

  • Relevant type checks, tests, and builds pass

  • No security-sensitive details or credentials are included

Screenshots or reproduction

<!-- refused: "… redirects to https://other.example. A package played with its own code, and a library bundle, are read only from the origin their address names: give its address on https://other.example." -->
<h5p-player trusted src="https://host.example/redirects-elsewhere.h5p"></h5p-player>
<!-- plays, as before -->
<h5p-player src="https://host.example/redirects-elsewhere.h5p"></h5p-player>

Summary by cubic

Closes #340. trusted and libraries vouch for an address, and the player followed redirects, so a trusted package or a library bundle whose address redirected to another origin played with that origin's code. Now only a redirect within the address's own origin is followed for them; one to another origin is refused (network), naming both.

This is a breaking change for player 2.x: such a package plays only when src names an address on the origin that serves it. A probe answered by the address's own origin marks the descriptor sameOrigin, and every later read—the Service Worker's range reads, the probe's size request, and the Jobs worker's download—holds to it. The mark comes from the address, not the load's mode, so two loads of one package agree. Untrusted packages still follow redirects, since their code does not run.