Security rules

NGB100: Untrusted import map

Reports import maps that let someone else decide which code a bare module specifier loads: entries in <script type="importmap"> of index.html that point at plain http:// URLs, script elements whose type is set to importmap and whose content is filled from an untrusted source, and importShim.addImportMap() (es-module-shims) with untrusted input..

Property Value
Rule ID NGB100
Category Supply chain
Default severity high
CWE CWE-829, CWE-494
Built-in presets recommended: error, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Reports import maps that let someone else decide which code a bare module specifier loads: entries in <script type="importmap"> of index.html that point at plain http:// URLs, script elements whose type is set to importmap and whose content is filled from an untrusted source, and importShim.addImportMap() (es-module-shims) with untrusted input.

Why it matters

An import map rewrites every import "x" of the page. Mapping a package to an HTTP URL lets a network attacker replace it; building the map from a query parameter or storage lets anyone who can send a link remap @angular/core or the app's own chunks to their script — full script execution in the app's origin without any HTML injection.

Detection behavior and supported patterns

  • <script type="importmap">{ "imports": { "lib": "http://…" } }</script> in the configured index.html (imports and scopes; loopback / private hosts excluded)
  • el.type = "importmap" or el.setAttribute("type", "importmap") and el.textContent | text | innerHTML = value on the same element variable, with value traced to an untrusted source
  • importShim.addImportMap(value) with value traced to an untrusted source

Example

TypeScript
script.type = 'importmap';script.textContent = JSON.stringify({ imports: { app: new URLSearchParams(location.search).get('app') } });

Safer alternative

TypeScript
<script type="importmap">{ "imports": { "app": "/assets/app-3f2a1c.js" } }</script>

Remediation

Keep import maps static and same-origin (or HTTPS with integrity metadata). Never build an import map from URL parameters, storage or messages; if overrides are needed for development, compile them out of production builds.

False-positive considerations

  • Maps built from a backend response you control are reported (medium confidence); validate the URLs against an origin allowlist before installing the map.

Known limitations

  • Import maps served by a backend or injected by SSR templates are not visible.
  • Only element variables within one file are correlated.

References

Run it

Shell
ngbastion explain NGB100