mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:40:52 +01:00
[PR #133] [MERGED] viewer: pin three.js CDN URLs with Subresource Integrity (OLD-8618) #187
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#187
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
5accc8eviewer: 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.jsand theutils/BufferGeometryUtils.jsit 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 carryintegrity+crossorigin="anonymous". The hash covers both the/vendor/copy thattools/gallery.pyserves and the CDN fallback.this.srcinonerror, and a script element that already ran never fetches again (checked in headless Chrome: the fallback script never loaded). It nowdocument.writes a new<script>with the CDN URL andthis.integrity, so it still runs before the scripts that follow it.tests/test_viewer_cdn_integrity.py(standard library). It checks that every remote URL inviewer/*.htmlhas an exact version and a sha384/sha512 hash, thatcrossoriginis 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. Withviewer/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.threer160 andGLTFLoader. A wrong hash in the map alone blocks the load, and so does a wrong hash in a preload link alone./vendor/loads r128,OrbitControlsandGLTFLoaderfrom 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
docs/design.md.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.