feat!: safe mode by default, trusted replaces untrusted (#323)

Merged
AL
5h ago
+533-433

Part of #323: safe mode by default, the element side. Embed's trust list and the untrusted SCORM zip, decided in #323, come in a second pull request on top of this one.

What changes (player 2.0)

  • Every package plays untrusted unless the page sets trusted: its own library folders ignored, libraries from libraries (default pack), content/ limited to H5P's file types, the content checked against the libraries' semantics. What untrusted did.
  • trusted (attribute and property) plays a package as it is, with its own code. The untrusted attribute and property are gone; setting the attribute asks for the default.
  • A message for the case the new default makes common: an untrusted package that neither the sources nor the package has a library for no longer says to set libraries, which it already has.

Everything that sets trust now

  • Verifier: untrusted by default; --trusted and the option trusted play the package's own code. --untrusted is still taken, so installed skills and older scripts run. The report keeps its untrusted field.
  • VS Code: h5pPreview.trusted, off by default, replaces h5pPreview.untrusted; the preview's Untrusted switch starts on; Restricted Mode stays untrusted.
  • Demo: the player page starts on Untrusted. The app and the cmi5 page play every package untrusted, files and same-site links too, and ask to play one with its own scripts only when it needs them, naming the file or the host. The pages with no setting take the site's own pack (demo/element.js).
  • MCP: the local server's check and preview play untrusted against the installed pack (partsFolder, now exported by h5p-author). The MCP app's play page plays the activity it built untrusted, from the pack copy it builds with.
  • Embed and SCORM, unchanged in behaviour: the embed site sets trusted where it trusts today (its own origin, listed hosts, a third-party frame), and the SCORM launch page sets trusted on the author's package. The second pull request changes both.
  • Docs, the skills and the demo pages lead with safe by default and trusted as the exception.

Breaking, for the release notes

  • A page that relied on the old default plays its packages untrusted: libraries from the pack (jsDelivr unless pack-base or pack), and a package that needs a library the pack lacks is refused with carried until the page sets trusted.
  • On such a page a package's revision changes, since it names the pack parts the package now plays against. Statements carry the new one. With resume="device" a learner's saved state starts over once: one saved against another revision is dropped, and the runtime says the content has changed. A resume="host" page that keys its saved state by revision sees the same.
  • player.untrusted = false no longer trusts a package.
  • h5p-verify plays untrusted unless --trusted.
  • VS Code: h5pPreview.untrusted is no longer read; h5pPreview.trusted plays with the package's own code.
  • Before the release: publish @missing-elements/h5p-libraries 1.1.2, which main names and every untrusted load now fetches.

Tests

  • Player 629 (the fixtures play trusted through the helper, since their content type is in no pack; untrusted plays say so), embed 83, verify 33, VS Code 30 and its suite in a real VS Code (8), demo 24 with two new cases (a same-site link plays untrusted; a file that needs its own code asks, naming it), author 335, MCP 24, MCP app 33, cmi5 50, journeys 56, skills 84. Typecheck and comments pass.

Release: player, verify and the VS Code extension major or breaking; the packages that pin the player follow at the bump.


Summary by cubic

Safe mode is now the default: every package plays untrusted — none of its own code runs, its libraries come only from the libraries sources (the pack by default), and its content is checked against the libraries' semantics — unless the page sets trusted. The untrusted attribute and property are gone; setting one asks for the default.

Breaking changes

  • A page that relied on the old default now plays its packages untrusted: a package that needs a library the pack lacks is refused with carried until the page sets trusted.
  • player.untrusted = false no longer trusts a package.
  • h5p-verify plays untrusted unless --trusted; --untrusted is still accepted and does nothing.
  • VS Code reads h5pPreview.trusted instead of h5pPreview.untrusted.
  • Before releasing, publish @missing-elements/h5p-libraries 1.1.2, which main names and every untrusted load now fetches.

What it touches

  • The verifier, the VS Code extension, the demo app, the cmi5 page, and the MCP server and app all default to untrusted; Embed and the SCORM page set trusted where they already trusted, so their behaviour is unchanged.
  • Docs, skills and the demo lead with safe by default and trusted as the exception.