viewer: pin three.js CDN URLs with Subresource Integrity (OLD-8618) #133
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!133
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/133/head"
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?
@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 UTCClaimed 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.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.