[PR #133] [MERGED] viewer: pin three.js CDN URLs with Subresource Integrity (OLD-8618) #187

Closed
opened 2026-11-26 20:17:04 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/133
Author: @ItsMrDubey
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: viewer-cdn-integrity


📝 Commits (1)

  • 5accc8e viewer: three.js loads from pinned CDN URLs checked by integrity hashes

📊 Changes

3 files changed (+209 additions, -3 deletions)

View changed files

➕ tests/test_viewer_cdn_integrity.py (+187 -0)
📝 viewer/index.html (+13 -0)
📝 viewer/studio.html (+9 -3)

📄 Description

Claimed in the coordination issue as: OLD-8618 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7119646964)

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/133 **Author:** [@ItsMrDubey](https://github.com/ItsMrDubey) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `viewer-cdn-integrity` --- ### 📝 Commits (1) - [`5accc8e`](https://github.com/ubiquitarianism/leonida/commit/5accc8ee21003d2d0edfae2953fd466944c77556) viewer: three.js loads from pinned CDN URLs checked by integrity hashes ### 📊 Changes **3 files changed** (+209 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_viewer_cdn_integrity.py` (+187 -0) 📝 `viewer/index.html` (+13 -0) 📝 `viewer/studio.html` (+9 -3) </details> ### 📄 Description Claimed in the coordination issue as: OLD-8618 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7119646964) ### 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`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:17:04 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#187
No description provided.