Security rules
NGB075: Untrusted worker script
Traces untrusted data (URL, postMessage data, window.name, referrer, HTTP responses, storage) into the script that a Web Worker, Shared Worker or service worker runs: the URL of new Worker(url), new SharedWorker(url) and navigator.serviceWorker.register(url), and the code of Blob workers (new Worker(URL.createObjectURL(new Blob([code])))).
| Property | Value |
|---|---|
| Rule ID | NGB075 |
| Category | Angular security & XSS |
| Default severity | high |
| CWE | CWE-829, CWE-94 |
| 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
Traces untrusted data (URL, postMessage data, window.name, referrer, HTTP responses, storage) into the script that a Web Worker, Shared Worker or service worker runs: the URL of new Worker(url), new SharedWorker(url) and navigator.serviceWorker.register(url), and the code of Blob workers (new Worker(URL.createObjectURL(new Blob([code])))). importScripts() inside workers is NGB005.
Why it matters
A worker runs with the page's origin: it can call your APIs with the user's cookies, read IndexedDB and CacheStorage, and post forged messages to the page. A service worker is worse — once registered it intercepts every request of its scope and survives reloads. Letting the URL or the code come from a query parameter or a message is script injection.
Detection behavior and supported patterns
new Worker(url),new SharedWorker(url)(DOM constructors),navigator.serviceWorker.register(url)/ServiceWorkerContainer.register(url)with a traced untrusted URL (data:andblob:URLs built from untrusted text included)new Worker(URL.createObjectURL(new Blob([code])))with untrustedcode- Not reported:
new Worker(new URL('./app.worker', import.meta.url))(Angular CLI worker bundles), constant URLs
Example
const worker = new Worker(this.route.snapshot.queryParams['engine']);Safer alternative
const worker = new Worker(new URL('./engine.worker', import.meta.url), { type: 'module' });Remediation
Load workers only from constant, same-origin URLs (new Worker(new URL('./x.worker', import.meta.url))) and register service workers from a fixed path. Pass untrusted data to the worker as messages, never as its URL or code.
False-positive considerations
- A worker URL chosen from a server response you fully control (configuration API) is reported with medium confidence; pin it to a constant or document an exception.
Known limitations
- Blob workers are followed when the Blob and object URL are created inline or in a local
const. - Worker URLs validated by an allowlist are still reported (the check is not recognized).
References
Run it
ngbastion explain NGB075