viewer: pin three.js CDN URLs with Subresource Integrity (OLD-8618) #133

Manually merged
github merged 1 commit from gh-pr/133/head into gh-pr/133/base 2026-11-26 08:45:51 +00:00
Owner

@⁠ItsMrDubey on GitHub · 2026-11-24 02:24 UTC · original
ItsMrDubey:viewer-cdn-integrity → main · +209 −3 · 3 files · 1 commits · merged 2026-11-24 03:09 UTC

Claimed in the coordination issue as: OLD-8618 (#14)

What and why

Old #8618: the viewer loaded three.js from CDNs with no integrity check, so a compromised or changed CDN file would run in the page.

  • viewer/index.html: the import map now has an "integrity" table (Chromium 127+, Firefox 138+, Safari 18+) for every file of the module graph: three.module.js, GLTFLoader.js and the utils/BufferGeometryUtils.js it imports. The same hashes are on <link rel="modulepreload" crossorigin="anonymous" integrity=...> links after the import map, so browsers without import-map integrity still check them (the imports reuse the preloaded fetch). Version stays pinned at [email protected].
  • viewer/studio.html: the three r128 classic scripts carry integrity + crossorigin="anonymous". The hash covers both the /vendor/ copy that tools/gallery.py serves and the CDN fallback.
  • Also fixed the studio fallback itself. It set this.src in onerror, and a script element that already ran never fetches again (checked in headless Chrome: the fallback script never loaded). It now document.writes a new <script> with the CDN URL and this.integrity, so it still runs before the scripts that follow it.
  • New tests/test_viewer_cdn_integrity.py (standard library). It checks that every remote URL in viewer/*.html has an exact version and a sha384/sha512 hash, that crossorigin is set, that fallbacks reuse the tag's hash, that the import map and modulepreload hashes agree, and that every module import resolves to a hashed URL. It also has checker cases built from hand-written HTML.

Hashes are sha384 of the files as served. jsdelivr and unpkg serve identical bytes for every 0.160.0 file, and cdnjs and jsdelivr serve identical bytes for r128 three.min.js. jsdelivr and unpkg also match for the r128 example files, so one hash per file is enough. No JS is vendored, since the repo doesn't vendor any.

Tested

Windows 11, Python 3.11.9, Node 22.23.2, no GPU needed.

  • python -I tests/test_viewer_cdn_integrity.py: 10 tests OK. With viewer/ from origin/main it fails (2 failures, 1 error).
  • python -I tests/test_viewer_serve.py: 39 OK (1 skipped). python -I tests/test_gallery.py: 29 OK.
  • node --test tests/test_viewer_streaming.cjs tests/test_viewer_studio.cjs: 67/68. The one failure ("Shift speeds the camera up…", AbortController is not defined) also fails on origin/main and is addressed by #13.
  • Headless Chrome 158, pages served from 127.0.0.1:
    • index.html's import map + preload block loads three r160 and GLTFLoader. A wrong hash in the map alone blocks the load, and so does a wrong hash in a preload link alone.
    • studio.html with no /vendor/ loads r128, OrbitControls and GLTFLoader from the CDN. With identical /vendor/ copies it loads them locally. With a tampered hash nothing loads.
  • python -I scripts/check_no_game_data.py viewer/index.html viewer/studio.html tests/test_viewer_cdn_integrity.py: clean.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • No new translator rule, so nothing to add to the contract table of docs/design.md.
**@⁠ItsMrDubey** on GitHub · 2026-11-24 02:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/133) `ItsMrDubey:viewer-cdn-integrity` → `main` · +209 −3 · 3 files · 1 commits · merged 2026-11-24 03:09 UTC Claimed in the coordination issue as: OLD-8618 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Old #8618: the viewer loaded three.js from CDNs with no integrity check, so a compromised or changed CDN file would run in the page. - `viewer/index.html`: the import map now has an `"integrity"` table (Chromium 127+, Firefox 138+, Safari 18+) for every file of the module graph: `three.module.js`, `GLTFLoader.js` and the `utils/BufferGeometryUtils.js` it imports. The same hashes are on `<link rel="modulepreload" crossorigin="anonymous" integrity=...>` links after the import map, so browsers without import-map integrity still check them (the imports reuse the preloaded fetch). Version stays pinned at `[email protected]`. - `viewer/studio.html`: the three r128 classic scripts carry `integrity` + `crossorigin="anonymous"`. The hash covers both the `/vendor/` copy that `tools/gallery.py` serves and the CDN fallback. - Also fixed the studio fallback itself. It set `this.src` in `onerror`, and a script element that already ran never fetches again (checked in headless Chrome: the fallback script never loaded). It now `document.write`s a new `<script>` with the CDN URL and `this.integrity`, so it still runs before the scripts that follow it. - New `tests/test_viewer_cdn_integrity.py` (standard library). It checks that every remote URL in `viewer/*.html` has an exact version and a sha384/sha512 hash, that `crossorigin` is set, that fallbacks reuse the tag's hash, that the import map and modulepreload hashes agree, and that every module import resolves to a hashed URL. It also has checker cases built from hand-written HTML. Hashes are sha384 of the files as served. jsdelivr and unpkg serve identical bytes for every 0.160.0 file, and cdnjs and jsdelivr serve identical bytes for r128 `three.min.js`. jsdelivr and unpkg also match for the r128 example files, so one hash per file is enough. No JS is vendored, since the repo doesn't vendor any. ### Tested Windows 11, Python 3.11.9, Node 22.23.2, no GPU needed. - `python -I tests/test_viewer_cdn_integrity.py`: 10 tests OK. With `viewer/` from origin/main it fails (2 failures, 1 error). - `python -I tests/test_viewer_serve.py`: 39 OK (1 skipped). `python -I tests/test_gallery.py`: 29 OK. - `node --test tests/test_viewer_streaming.cjs tests/test_viewer_studio.cjs`: 67/68. The one failure ("Shift speeds the camera up…", `AbortController is not defined`) also fails on origin/main and is addressed by #13. - Headless Chrome 158, pages served from 127.0.0.1: - index.html's import map + preload block loads `three` r160 and `GLTFLoader`. A wrong hash in the map alone blocks the load, and so does a wrong hash in a preload link alone. - studio.html with no `/vendor/` loads r128, `OrbitControls` and `GLTFLoader` from the CDN. With identical `/vendor/` copies it loads them locally. With a tampered hash nothing loads. - `python -I scripts/check_no_game_data.py viewer/index.html viewer/studio.html tests/test_viewer_cdn_integrity.py`: clean. AI-assisted: yes ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] No new translator rule, so nothing to add to the contract table of `docs/design.md`.
index.html hashes the three.js module graph in its import map and modulepreload links; studio.html hashes its three classic scripts and its CDN fallback, which document.write now actually loads (setting src on a failed script never refetched). tests/test_viewer_cdn_integrity.py checks every remote URL in viewer/*.html.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:45:49 +00:00
github manually merged commit 5accc8ee21 into gh-pr/133/base 2026-11-26 08:45:51 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.