Skip to content

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

Merged
alekswebnet merged 1 commit into
mainfrom
fix/code-from-its-origin
Dec 3, 2026
Merged

alekswebnet merged 1 commit into
mainfrom
fix/code-from-its-origin

Conversation

@alekswebnet

@alekswebnet alekswebnet commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

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 feat(embed)!: every package untrusted unless --trusted names it (#323) #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.

Written for commit 173d3a8. Summary will update on new commits.

View guided diff Turn on auto-fix

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9f717b6 and 173d3a8.

Files selected for processing: 11

  • design/security.md
  • docs/api.md
  • docs/untrusted.md
  • packages/player/README.md
  • packages/player/src/h5p-offline-player.ts
  • packages/player/src/jobs/jobs-worker.ts
  • packages/player/src/shared/protocol.ts
  • packages/player/src/shared/source.ts
  • packages/player/tests/browser/redirects.test.ts
  • packages/player/tests/unit/source-probe.test.ts
  • packages/player/vite.plugins.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…n their address names (#340)

trusted and libraries vouch for an address, and fetch follows redirects,
so a redirect let another origin choose the code. The probe of a trusted
package and of a bundle now refuses a response a redirect brought from
another origin, naming both; a redirect within the origin is followed.
A probe the address's own origin answered marks the descriptor
sameOrigin, and the worker's range reads and the Jobs worker's download
hold to it. An untrusted package still follows redirects.
@alekswebnet
alekswebnet force-pushed the fix/code-from-its-origin branch from ee57759 to 173d3a8 Compare December 3, 2026 08:58
@alekswebnet
alekswebnet merged commit 03e4b4a into main Dec 3, 2026
16 checks passed
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.

Player: read a trusted package and a library bundle only from the origin their address names

2 participants