This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run build # Compile TypeScript to dist/
npm run watch # Watch mode compilation
npm run typecheck # Type-check without emitting
npm run lint # ESLint with auto-fix
npm run check # lint + typecheck
npm test # Run all tests (node:test via tsx)Run a single test file:
tsx --test tests/schematest.tsRun from source (dev):
npm run start -- <url> [-v] [--sbom]The scanner uses Puppeteer to load a target URL in a headless browser, intercepts all JavaScript responses, then runs each script through the retire.js vulnerability database.
Data flow:
index.ts— CLI entry point. Parses args, wires callbacks, callsbrowser.load().browser.ts— Launches Puppeteer, registerspage.on("response")to capture JS payloads. Retries failed body reads viarequest.ts. Detects third-party domains viasuffix-list.tsand reports them as services.retireWrapper.ts— Fetches the retire.js repo JSON from GitHub at startup (jsrepository-v3.json). Exposes aScannerobject with four methods:scanUri,scanContent,runFuncs,scanUrlBackdoored. TherunFuncsmethod evaluates JS expressions in the live browser page to detect libraries by their global variables.sourceMapResolver.ts— For each JS URL, attempts to fetch.map/.js.mapfiles and unpacks them viasource-mapto expose original source for deeper scanning.log.ts— Dual-mode logger. Default mode (consoleLogger) prints to stdout/stderr. When--sbomis passed,useJson()switches tojsonLogger, which collects all results and emits a CycloneDX 1.4 JSON document onclose().--sbom-filewrites that document to a file instead of (or in addition to) stdout.
Key design details:
- The retire.js vulnerability DB is always fetched live from GitHub — no local copy bundled.
- Backdoor detection (
scanUrlBackdoored) uses regex patterns from thebackdooredkey in the repo JSON to flag known supply-chain compromise URLs. - The
suffix-list.tsmodule is used to determine the registrable domain for service tracking (distinguishing first-party from third-party requests). - CycloneDX output (
convertToCycloneDXinlog.ts) includes components, vulnerabilities, and services sections. Tests validate the output againstbom-1.4.schema.json.
Output modes:
- Default: human-readable console output; warnings go to stderr, info to stdout.
--sbom: machine-readable CycloneDX JSON on stdout; all log messages redirected to stderr.--sbom-file <path>: same JSON written to a file; console output resumes normally.