Skip to content

fix(tech-detect): the URLs an import map maps to are script URLs #1539 - #1542

Closed
nc9 wants to merge 4 commits into
mainfrom
fix/1539-importmap-urls
Closed

nc9 wants to merge 4 commits into
mainfrom
fix/1539-importmap-urls

Conversation

@nc9

@nc9 nc9 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1539.

Reproduced on v0.0.159 (ea60499), detectTechnologies on parts-built pages

Shape threejs
<script type="importmap"> mapping three to jsdelivr three.module.js not detected
the same with a self-hosted ./vendor/three/build/three.module.js not detected
inline <script type="module">import * as THREE from '<cdn>/three.module.js' detected
<script src=...three.min.js> and <script type="module" src=...three.module.js> detected

So the inline module case in the issue is already satisfied on main (its text is read as inline text up to 16 KB); the import map is the gap. An import map is in DATA_SCRIPT_TYPE, so its body was never read and its URLs were never script URLs.

What changes (packages/tech-detect/src/detect.ts)

In the page pass, a <script type="importmap"> is parsed as JSON and the string values of its imports table and of each scopes table are kept as script URLs: one synthetic <script type="module" src="..."> tag per URL goes into the markup for the URL patterns, and a collected script with that src for the tag-attribute detectors. Bounded: a map over 65,536 characters (UTF-16 code units, not bytes) is not parsed, at most 256 URLs a map and 512 a page, at most 64 KB of synthetic tags a page, at most 2,048 characters a URL. Only an http or https URL or a path starting with /, ./ or ../ is kept (a bare name and any other scheme are rejected, as browsers reject them), and a value with a quote, angle bracket, backtick, backslash, whitespace, control character (C0, DEL, C1) or lone surrogate is rejected, so each synthetic tag is exactly one well-formed script tag with the URL as its src (a "><script src=//evil.example/x.js> value cannot add a tag or an attribute). An entry past a bound or rejected is counted internally (pageImportMapSkipped, in no report) and not read; the rest of the page is read as usual. The map itself and its keys stay out of the markup; malformed JSON, a map without imports or scopes, non-string values and other data types (JSON-LD, application/json, __NEXT_DATA__, speculation rules) are unchanged. Relative values are matched as written: resolving them against the page URL adds nothing a pattern can match (a host-anchored pattern cannot match a same-origin path, and the path patterns match ./vendor/three/... as is), so AC3's resolution is not implemented; lane-review-prs to amend with the original text kept.

Tests (importmap-1539.test.ts, 41; failing first: 4 fail on main)

  • three.js through an import map on jsdelivr, unpkg, cdnjs, a self-hosted relative path and an absolute path; the scopes table; a map in the body; an uppercase type with extra attributes; several maps; an import map finds whatever the same URL finds in a <script type="module" src> (three.js, Tag Manager, Meta Pixel). An inline module with a static import, a namespace import and import() of a three.module.js URL (already detected on main).
  • Bounds, by counts: a 70 KB map is skipped and counted; the 65th URL of a map is not read; a 2,100-character URL is skipped; 9 maps of 64 URLs give 512 synthetic tags and 64 counted; 2,000-character URLs stop at the 64 KB byte bound.
  • Forged URLs ("><script src=//evil-three.example/three.js>, a URL with a newline, a space, ', a backtick, <, >, a backslash, javascript:, data:, blob:): no synthetic tag, one skip counted, no detection, and the markup never contains the forged host; next to a good URL the markup holds exactly one synthetic tag for it. http, https, protocol-relative and relative URLs are all kept.
  • Hostile pages: a map of 100,000 entries and a 5 MB map are skipped (one counted, no tag); 100,000 tiny maps give 512 synthetic tags and 99,488 counted (4.8 MB page, 1.8 s against 1.3 s for a plain page at load 13); 200 scopes of 5 URLs in one map read 64.
  • Precision: the word importmap in prose or a comment, a data-importmap attribute, JSON in a application/json script and a map of other vendors detect nothing; CSP, anchor, JSON-LD, __NEXT_DATA__, speculation rules and prose as before.
  • Review round: a double quote with no space or bracket (a"data-evil="1, a"/onload="1) adds no attribute; each of quote, ', backtick, <, >, backslash, space, a C0 character, DEL, U+0085, U+2028, U+2029 and a lone surrogate is rejected in its own test; boundaries: map 65,536 and 65,537 characters (and 21,846 three-byte characters, read), URL 2,047, 2,048 and 2,049, 32 tags of 2,048 characters fill the 64 KB bound exactly and one character more drops the last, the 256th and 257th URL of a map; HTTPS:// accepted, empty and bare values rejected, array-valued imports and scopes ignored, importmap-shim, application/importmap+json, x-importmap and importmaps not read. The per-map bound is 256 (64 junk entries before the real one used to drop it). Mutants of every bound (>= and +1), each character class member, the lone-surrogate halves, the address pattern and its case flag, and the type test (contains, prefix, case) fail a test; two members that were duplicates (U+2028 and U+2029 inside \s, and the empty check inside the address pattern) were removed as equivalent.
  • A map with only a scopes table counts (scoped mappings are real); an entry the page never imports still counts (evidence, not proof); a map inside a <template> is inert and is not read (nested templates, a template closed before the map, and an uppercase tag are tested; four mutants of the depth tracking fail); a map inside <noscript> or <svg> is read as before. importmap-shim is out of scope.
  • Mutants (each restored from a clean copy): each of the six bounds made unbounded, the unsafe-character test removed and with each of quote, backslash and whitespace dropped from it, the scheme test removed, the per-map limit removed, the markup push removed, the collected push removed, the scopes table removed and the type test loosened to json each fail a test.
  • script-url-wrappers-1435.test.ts: the import map line is removed from its "still not read" list (a map to a clarity URL now counts, by this change).

Docs (docs/cloud/technologies.mdx) and CHANGELOG updated. No fingerprint changes, so generated.ts is untouched. Existing tech-detect (140 + 87 tests) and audit-engine tech tests (48) pass. Skill change: none. The corpus A/B (v0.0.159 against this head, threejs and every other detection) is for squirrelscan-53.

nc9 added 3 commits November 2, 2026 17:51
…well-formed http(s) or relative values; skips counted #1539

Signed-off-by: Nik Cubrilovic <[email protected]>
…-only and unimported entries documented and pinned #1539

Signed-off-by: Nik Cubrilovic <[email protected]>
…surrogate values rejected, boundaries and quote forging pinned #1539

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Shipped in v0.0.160. The commits were cherry-picked onto the release branch and rebase-merged: c23c8e1 8b97ba8 fab4d37 7aabe2b.

Closing this PR since the change is on main.

nik

@nc9 nc9 closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tech detection: three.js loaded through an import map or an inline module import is not detected

1 participant