feat(embed)!: every package untrusted unless --trusted names it (#323)
Summary
Part of #323: the second half of safe mode by default, after #324. The embed site and the SCORM zip play every package untrusted unless the host says it made it, as decided in #323. The issue stays open for the SCORM Cloud check decided there.
Changes
Embed site
- Every package plays untrusted, its own origin's and a
--packageshost's too, framed by another site or not. Until now all three played with their own code. --trusted <origins>(trustedtobuildSiteandstartEmbed) names the origins whose packages play with their own code;selfis the site's own. Each must be on--packageswhen there is one, checked when the site is written.config.jscarries the list.--packagesonly says who may play. The button to play with its own code stays, offered only to a package that cannot play without it. After the click the package plays as a trusted origin's does: as exported, without the pack the untrusted try took.- A trusted origin's link may name a bundle in
libraries=only on a trusted origin, or the page refuses the address: a bundle's code runs whatever the package's trust. Found while fixing the redirect finding in review; the redirect itself is #340, in the player. askInOwnFrame: false, for a site's own preview, plays untrusted first and gives a package that needs its own code its code without the button, in a frame of the page's own origin only. Opened by its address, or framed by another site, the page asks.
SCORM zip
- Untrusted by default: the launch page drops
trusted, and the writer plans as the element plays untrusted, every library from the pack. - Content made for a newer minor of a library than the pack has plays at the pack's, as the element plays it on a site (#85): the writer plans the older part, and the command, the page's row and
downgradedon the result say which. Until now such a package was refused. Decided in review: the zip does what the site does. --trustedwith--scorm(trustedtobuildScorm,planScormInPage,buildScormInPage) plays the package's own code.--trustedis a switch beside--scormand a list without it, so the command reads--scormfirst, and refuses the site's form (--trusted self) beside--scorm.- A package that carries a library the pack has no version of is refused naming
--trusted, andEmbedError.carriedis set for a caller to word its own hint. - The SCORM page has a "Play each package with its own code" switch in step ②, so it can be reached when every row is refused. Turning it reads every row again, keeps the titles typed, and drops a read the turn overtook.
NOTICE.txtin the zip says which the pack's parts are: those the package plays with, or, trusted, those it does not carry.
Player: olderThanAsked, the rule for a library served older than asked, moves to shared/library-folders.ts and is exported from ./plan, so the writer names a downgrade as the worker does. No change in behaviour.
Docs: design/embed.md, design/scorm.md, design/demo.md, the embed README (the options, the address parameters, the SCORM section), docs/compatibility.md, the h5p-to-scorm skill, the setup skill's embed reference, and the demo's setup and SCORM pages.
Breaking, for the release notes (embed major)
- A site written again plays every package untrusted, its own and its listed hosts' too. Write it with
--trusted self https://host.examplefor packages that need their own code. - The address's
libraries=andrefresh-libraries=offcount only for a package from a trusted origin, and a bundle there must be on a trusted origin too. Any other plays with the site's sources:--default-libraries, else the pack. So an export without libraries now plays with nolibraries=in its address. - After the button, a package plays as exported: the site's pack no longer fills or refreshes it.
askInOwnFrame: falseno longer plays a package as it is at once.- A zip written again plays untrusted. It carries the pack's libraries beside the package's own (the demo quiz: 2.8 MB → 4.3 MB), and its build stamp changes, so learners' saved places start over once.
- A package made for a newer minor than the pack has is written, at the pack's version, where it was refused. One that carries a library the pack has no version of is refused unless
--trusted. - A host's own SCORM page without the switch writes untrusted zips unless
startScormPage({ trusted: true }).
Verification
-
pnpm --filter @missing-elements/h5p-embed test: 96 passed (83 onmain). New or changed:- site: own origin, framed and listed hosts untrusted;
selfand listed origins trusted; the preview without the button in its own frame, and with it at its address and in another site's frame; the pack gone after the click; a bundle on an untrusted origin refused for a trusted package, one on its own origin taken; - SCORM: the untrusted zip; the older minor planned, said by the command and played in the stand-in LMS, where the element reports the same downgrade; the
carriedrefusal and the trusted zip; the refused--trusted self; - in-page builder: both modes and the older minor against the command, entry for entry; the no-pack refusal;
- page: the switch re-reads rows and names itself in a refusal; a row says its older version; a read that failed does not outlive a later one that worked.
- site: own origin, framed and listed hosts untrusted;
-
Player unit 419,
apps/skillsto-scorm.test.ts4, on this branch. -
pnpm typecheck,pnpm lint,pnpm comments: pass. -
A
--trustedzip againstmain's, for both demo packages: every file the same buth5p-sw.js, the player's worker, whose build differs by four bytes with the moved function. -
Not done: an untrusted zip in a real LMS. SCORM Cloud comes next, before the release.
-
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
npx h5p-embed --scorm own-code.h5p # written: "Plays at an older version … H5P.QuestionSet 1.99 → 1.21.x"
npx h5p-embed --scorm custom.h5p # refused: "Played untrusted … Pass --trusted …"
npx h5p-embed --scorm custom.h5p --trusted
own-code.h5p is the demo quiz with its Question Set renamed 1.99, and custom.h5p the quiz with a library the pack has at no version (ownCodeQuiz and customQuiz in tests/helpers/zip.ts).
Summary by cubic
Makes untrusted playback the default: the embed site plays every package without its own code—its own origin's, a --packages host's, and in another site's frame—and SCORM zips play untrusted with every library from the pack. --trusted names the origins whose packages run their own code (self for the site's own); each must be on --packages when there is one. The SCORM page gains a "Play each package with its own code" switch, and startScormPage({ trusted: true }) opts a host's own page in.
Breaking
- A site or zip written again plays untrusted; pass
--trusted self https://host.examplefor packages that need their own code. askInOwnFrame: falseno longer plays a package as it is at once: it plays untrusted first and gives a package that needs its own code the code without the button.- Untrusted zips carry the pack's libraries beside the package's own (demo quiz: 2.8 MB → 4.3 MB), play a package made for a newer minor at the pack's older one, and change the build stamp, so learners' saved places start over once.
- A package that needs a library the pack lacks is refused unless
--trusted; the refusal setsEmbedError.carriedfor a caller to word its own hint.