kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

H5P and Bloom request a peer's zipcontent files from the local server

Open rtibblesbot opened this issue 2 weeks ago • 9 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: release-v0.20.x

Observed behavior

  • H5PRunner.js:141-145 and BloomRunner.js:108-112 build zipcontentUrl from the last / segment of the storage URL.
  • A peer's storage URL carries the peer as ?baseurl=<peer>, so the zipcontent URL drops the peer and points at the local server.
  • H5P also builds its content path, library fallback and urlLibraries from zipcontentUrl (L241, L297, L419), so those requests go to the local server too.
  • #15820 fixes the Bloom side on develop only.
  • Reported by rtibbles in a review of #15820.

Steps to reproduce

  1. Browse a peer's library that has an H5P resource containing a file over the large-file threshold (e.g. a video).
  2. Open the resource and watch the network tab: the large file is requested from the local zipcontent/<file>.h5p/....

Acceptance Criteria

  • [ ] For a storage URL with ?baseurl=<peer>, H5P and Bloom request every zipcontent file from zipcontent/<encoded peer>/<file>/<path>.
  • [ ] Local storage URLs keep requesting zipcontent/<file>/<path>.
  • [ ] H5PRunner and BloomRunner build the URL with one shared helper.
  • [ ] Jest tests in the H5P and Bloom viewers cover both cases.

AI usage

Claude Code drafted this from rtibbles's review finding on #15820 and read the H5P and Bloom runner code to confirm the URL construction. I widened it to Bloom and to every zipcontentUrl use for 0.20.

rtibblesbot avatar Nov 20 '26 04:11 rtibblesbot

Widened for 0.20: BloomRunner.js on release-v0.20.x has the same bug (#15820 fixes it on develop only), and H5P's other zipcontentUrl uses also miss the peer. Both runners should share one URL helper.

rtibbles avatar Nov 24 '26 20:11 rtibbles

Checked the body against release-v0.20.x: the Bloom and H5P line refs (H5P L141/241/297/419, Bloom L108) match, and the shared-helper acceptance criterion covers both runners. No edits needed.

rtibblesbot avatar Nov 24 '26 22:11 rtibblesbot

Plan: H5PRunner and BloomRunner build their zipcontent URL with one helper that keeps a storage URL's ?baseurl=<peer> as zipcontent/<encoded peer>/<file>.

  • [ ] Shared helper, adopted by BloomRunner
  • [ ] H5PRunner adopts the helper
  • [ ] Self-review the produced code

Assumptions — the issue did not settle these; say so if one is wrong.

  • Helper lives in kolibri-sandbox as kolibri-sandbox/zipcontent; if wanted in kolibri-zip, the file and two imports move, behaviour unchanged.
  • This PR leaves #15820 alone; if it should adopt the helper before this forward-merges, develop's BloomRunner.js needs that edit there.
  • The real kolibri-zip over xhr-mock drives H5PRunner.init through to shimH5P in jsdom — not run, the planning worktree has no node_modules; Bloom's equivalent is proven by develop's spec. If it can't be made to pass, H5P's spec keeps jest.mock('kolibri-zip') and reads the large-file generator from ZipFile.mock.lastCall, and the PR body names that seam.
  • xhr-mock matches a storage URL carrying an unencoded ?baseurl=http://…/ — #15820's spec only exercises the encoded form. If it doesn't, register the handler with a regex; the string passed to init stays unencoded, as the server emits it.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 25 '26 02:11 rtibblesbot

Decided without asking; a reply here changes it.

  • Video: this PR leaves the 0.20 Bloom Player's URL rewrite alone, and a follow-up issue is drafted for it. The player prefixes every src that is not blob: with the book's blob URL, so a video of 500 KB or more never loads, for local books as well as a peer's, and in v0.19.4 and v0.19.5 too. "An acceptance criterion is not met without it" pointed to fixing here; "the work is in another repository" outweighed it, because static/bloom/ is built from learningequality/bloom-player's patched branch, which I cannot push to, and this branch did not cause the defect. Until the follow-up lands, Bloom's half of the first criterion holds for the URL BloomRunner writes into the book, which the spec asserts, and not in the browser; H5P's half holds in the browser.
  • Audio: same decision, same follow-up issue. BloomRunner writes narration and background audio as _<last URL segment> and the player rebuilds that as a blob URL, so audio of 500 KB or more is silent, local or peer. The same two lines applied with the same weighing; develop already carries both fixes as patches 0003 and 0006 of its in-tree player build.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 25 '26 03:11 rtibblesbot

Decided without asking; a reply here changes it.

  • Peer addresses with a path prefix and no trailing slash (http://peer:8080/kolibri): left alone, with no follow-up issue. Nothing Kolibri stores has that shape: NetworkClient.connect() rewrites every saved peer address to end in / (…/kolibri/api/public/info/ → …/kolibri/), zeroconf builds it from a URL_PATH_PREFIX that the options validator ends in /, and the learn pages send device.base_url unchanged, so only a hand-typed request carries one. "An edge case with no known affected user" outweighed "same defect at a sibling site": the join that drops the prefix is urljoin in kolibri_whitenoise.py:473 and join_url, which this branch does not touch and which fails the archive's own /content/storage/ fetch on release-v0.20.x before either runner builds a URL. For such an address every peer file stays broken, as it is today; the helper passes the peer through as given, and …/kolibri/ requests zipcontent/http%3A%2F%2Fpeer.example%3A8080%2Fkolibri%2F/<file>/<path>.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 25 '26 05:11 rtibblesbot

Decided without asking; a reply here changes it.

  • Debian kolibri-server: this PR leaves its nginx/uWSGI path handling alone, and a follow-up issue is drafted for it. nginx's uwsgi_params sets PATH_INFO to the decoded, slash-merged $document_uri, so zipcontent/http%3A%2F%2Fpeer.example%3A8080%2F/<file>/<path> reaches Kolibri as zipcontent/http:/peer.example:8080/<file>/<path>, which path_regex in zip_wsgi.py does not match: 404. That is already true on release-v0.20.x for every zipContentUrl caller (HTML5, safe HTML5, Perseus, QTI, custom channels) and has been since 48c731b5a1 (June 2023); no open issue or PR covers it. "The issue not naming a host is not a reason to defer" and "fix whatever puts the change where users meet it" pointed to fixing here; "a new mechanism in another subsystem, which this branch neither broke nor needs" outweighed them. The fix changes how the zip content server reads its path, or the nginx config kolibri-server generates, for every archive renderer, and nginx and uWSGI do not run in the agent's sandbox to check it. This branch causes no regression there: on kolibri-server a peer's large H5P and Bloom files return 404 before and after it, and on Kolibri's built-in server, which keeps %2F encoded, they now load. The PR body will say kolibri-server is not covered.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 25 '26 06:11 rtibblesbot

Decided without asking; a reply here changes it.

  • Self-review: another round runs instead of pushing, because the blocking finding is true. With the wait for the H5P frame's load event deleted from H5PRunner.js (L173-175), the uncommitted H5PRunner.spec.js passes 13 of 13 and the committed one fails starts H5P once, however many times the host page loads, so the uncommitted edit deletes the only test of that wait. "A blocking finding remains" and "work already written on the branch, related and small: keep it" pointed to another round; "a test nobody asked for is never a reason to fix here" pointed to pushing, since release-v0.20.x's spec also passes with the wait deleted and this PR does not change the wait. The first two outweighed it: the guard is already committed on this branch, and restoring it is one test. Direction for the round, in that test only:
    • Leave H5P off the host page and drop startWithFrameLoad.
    • Give the iframe a contentDocument getter that returns { readyState: 'loading', URL: 'about:blank' } and schedules one load with setTimeout.
    • Before start(), register a once load listener that sets hostPage.H5P.
    • After await start(), dispatch a second load and expect one H5P.init call.
    • This needs no addEventListener spy; run in the sandbox, it passes on the real runner (13 of 13) and fails with the wait deleted.
    • Rename SIMPLE_PEER_URL to PEER_URL, and keep the uncommitted path-prefix case in BloomRunner.spec.js.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 25 '26 09:11 rtibblesbot

Decided without asking; a reply here changes it.

  • Peer addresses whose path prefix holds a percent escape (http://peer.example:8080/my%20school/): left alone, with no follow-up issue and no change to how the zip content server reads its path. Such a peer already fails one step earlier, on release-v0.20.x and on this branch: the storage URL the server emits carries the peer raw (contentnode/base.py:283), the storage route reads it as my school/, which is not a known peer, and the archive itself returns 404 before either runner builds a URL. Run in the sandbox against a peer stored as …/my%20school/: storage lookup fails for the emitted URL; the zipcontent 404 is reached only with a hand-encoded ?baseurl=, which no Kolibri code emits. Plain and /kolibri/-prefixed peers return 200 on both routes. "An acceptance criterion is not met without it" and "the issue not naming a host is not a reason to defer" pointed to fixing here; "an edge case with no known affected user", "a new mechanism in another subsystem, which this branch neither broke nor needs" and the earlier decision on slash-less prefixes outweighed them: keeping the escape through Cheroot's decoding and unquote in zip_wsgi.py:334 changes the route for HTML5, Perseus and QTI too, which build the same segment (packages/kolibri/urls.js:200-203), and would still not make such a peer load. For these peers every file stays broken, as it is today. The self-review finding resolves declined, citing the plan's "Inherited from the zipcontent route"; the PR's review notes already list it as accepted.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 25 '26 11:11 rtibblesbot

Fixed in #16042

rtibbles avatar Nov 25 '26 20:11 rtibbles