npm audit Executor¶
Category: Software Composition Analysis
Script: npm_audit.py
Integration: CLI
Faraday Plugin: Raw JSON
Website: https://docs.npmjs.com/cli/v10/commands/npm-audit
Description¶
Runs npm audit on a Node.js project and imports each security advisory into Faraday as a vulnerability. You can audit a local directory or clone a Git repository.
Prerequisites¶
npminstalled and available in the agent'sPATH(checked withnpm --version)git, if you audit a repository by URL- A Node.js project with a
package-lock.jsonornpm-shrinkwrap.json - Network access to the npm registry, which
npm auditqueries for advisories
Configuration¶
Environment Variables (Setup)¶
| Variable | Required | Description |
|---|---|---|
GIT_USERNAME |
No | Username for cloning private repositories over HTTPS (default: oauth2) |
GIT_TOKEN |
No | Access token for cloning private repositories over HTTPS |
Execution Arguments¶
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
NPM_AUDIT_TARGET |
string | No* | Path to the Node.js project directory, which must contain package-lock.json or npm-shrinkwrap.json. When NPM_AUDIT_GIT_URL is set, it is a subpath inside the cloned repository (e.g., apps/frontend/). |
NPM_AUDIT_GIT_URL |
url | No* | Git repository to clone and audit |
NPM_AUDIT_GIT_REF |
string | No | Branch or tag to clone (default: the repository's default branch) |
NPM_AUDIT_PRODUCTION_ONLY |
boolean | No | When true, skips devDependencies (runs npm audit --omit=dev). Default: false. |
NPM_AUDIT_MIN_SEVERITY |
string | No | Minimum severity to import: info, low, medium, high or critical (default: info) |
* You must set NPM_AUDIT_TARGET, NPM_AUDIT_GIT_URL, or both.
YAML Configuration Example¶
executors:
npm_audit:
repo_executor: npm_audit.py
max_size: 65536
varenvs:
GIT_USERNAME: "<git_username>"
GIT_TOKEN: "<git_token>"
params:
NPM_AUDIT_TARGET:
mandatory: false
type: string
base: string
NPM_AUDIT_GIT_URL:
mandatory: false
type: url
base: string
NPM_AUDIT_GIT_REF:
mandatory: false
type: string
base: string
NPM_AUDIT_PRODUCTION_ONLY:
mandatory: false
type: boolean
base: boolean
NPM_AUDIT_MIN_SEVERITY:
mandatory: false
type: string
base: string
How It Works¶
- If
NPM_AUDIT_GIT_URLis set, makes a shallow clone of the repository (atNPM_AUDIT_GIT_REF, if given) into a temporary directory. For HTTPS URLs it authenticates withGIT_USERNAME/GIT_TOKEN. - Runs
npm audit --jsonin the project directory (with--omit=devwhenNPM_AUDIT_PRODUCTION_ONLYistrue) - Parses the report. Both the npm 7+ format and the older npm 6 format are supported.
- Maps each advisory to a Faraday vulnerability:
- Name:
[npm-audit] <advisory title> - Severity: npm's severity, with
moderatemapped to medium - Description: the package, vulnerable range, dependency paths and advisory overview
- References: the advisory URL, CVEs and CWEs
- Data: the package and the version that fixes it, when npm reports one
- Name:
- Drops advisories below
NPM_AUDIT_MIN_SEVERITYand deletes the temporary clone
Notes¶
- The executor creates a single host per run. Its IP is
0.0.0.0and its hostname is thenameinpackage.json, or the directory name when there is none. - An advisory that affects several packages is imported only once.
npm audittimes out after 10 minutes.- An unrecognized
NPM_AUDIT_MIN_SEVERITYvalue falls back toinfoand is written to the agent log. - The shared agent parameters (
AGENT_CONFIG_*tags and severity filters) are not applied by this executor. UseNPM_AUDIT_MIN_SEVERITYto filter by severity.