fix(player): an entry inflates no further than the size its archive declares, and the worker parses no JSON over 16 MB

Merged
AL
18h ago
+337-16

Two limits on what an archive's sizes can cost the player. Found in a review of the player's code, with no report from outside.

What was open

  • The native DecompressionStream knows no declared size. An extraction in the Jobs worker, the warm and a reader over an archive still downloading inflate with it, so an entry could inflate past the size its archive declares: 65 kB inflated to 64 MB under a declared 10 bytes and was recorded in the chunk store as complete. Without end, it fills the store, and each refused write evicts another idle package.
  • A stored entry went down the same path as it was: one that declared 10 bytes gave its 4 MB to a reader over an archive still downloading (found in cubic's review).
  • zip.js, which reads for a reader over the central directory, already refuses either entry as it streams, so that path was not open.
  • The Service Worker parsed h5p.json, library.json and content.json whole, whatever their size: a 33 kB archive made it parse 32 MB.

Fix

  • inflated (shared/stream-utils.ts) takes the entry, counts its output, a stored entry's too, and fails with bad-archive past the declared size (heldTo). Its three callers pass the entry: the extraction, the warm and PackageReader.inflateDirect.
  • PackageReader.json refuses, unread, an entry that declares or carries more than PARSED_MAX_SIZE (16 MB), and every JSON parse in the worker goes through it: readManifest, the content's parameters, the addons and the server's readJson.
    • An oversized h5p.json fails the package, and an oversized library.json the load that needs it, with the limit in the message.
    • An oversized content.json is treated as one that cannot be parsed, and the addon scan passes over an oversized library.json, as over one that does not parse.
    • The limit is on the larger of what the entry declares and what the archive carries for it (parsedSize), and a read is held to the declared size.
    • The largest content.json of 89 real packages is 150 kB.
  • design/security.md: the rule, and what stays unbounded.

Not bounded

  • The archive's index, which zip.js reads whole whatever its entry count.
  • An entry of an honest, enormous size: a large package like any other, which evicts idle ones to fit.

Tests

  • tests/unit/declared-size.test.ts, twelve tests: the native path cut off at the declared size, deflated and stored; an honest entry passed whole; nothing complete in the chunk store; both kinds of reader; and the JSON limit for each of the three files, for a stored file that carries more than it declares, for one that carries more than the limit, and at the limit itself.
  • tests/unit/warm.test.ts: an entry past its size is passed over, and the rest lands.
  • tests/browser/jobs-worker.test.ts: through the real Jobs worker, the extraction fails with bad-archive and keeps no chunk.
  • Player: type check, 414 unit tests, 215 browser tests in Chromium with the slow files, pnpm comments.
  • Not run: Firefox and WebKit.

Release: a player patch (SECURITY.md: a security fix ships in any release). An entry that runs past its declared size was read before and fails now; a JSON file over 16 MB was parsed before and is refused now.


Summary by cubic

Stops a hostile archive's sizes from costing the player more than declared: an entry now inflates no further than the size its archive declares, and the worker parses no JSON over 16 MB.

  • inflated() counts output and fails with bad-archive past the declared size, for deflated and stored entries alike. The native DecompressionStream, which knows no declared size, previously inflated entries to their end; stored entries were returned as carried.
  • PackageReader.json refuses, unread, a JSON entry declaring or carrying more than PARSED_MAX_SIZE, as parsing holds it whole. An oversized h5p.json or library.json fails the package, while an oversized content.json is treated as one that cannot be parsed; the addon scan passes over such a library.json.

Behavior change: entries that inflated past their declared size and JSON over 16 MB were accepted before and are now refused. This is a security fix, shipped in a player patch.