Skip to content

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

  • npm installed and available in the agent's PATH (checked with npm --version)
  • git, if you audit a repository by URL
  • A Node.js project with a package-lock.json or npm-shrinkwrap.json
  • Network access to the npm registry, which npm audit queries 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

  1. If NPM_AUDIT_GIT_URL is set, makes a shallow clone of the repository (at NPM_AUDIT_GIT_REF, if given) into a temporary directory. For HTTPS URLs it authenticates with GIT_USERNAME/GIT_TOKEN.
  2. Runs npm audit --json in the project directory (with --omit=dev when NPM_AUDIT_PRODUCTION_ONLY is true)
  3. Parses the report. Both the npm 7+ format and the older npm 6 format are supported.
  4. Maps each advisory to a Faraday vulnerability:
    • Name: [npm-audit] <advisory title>
    • Severity: npm's severity, with moderate mapped 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
  5. Drops advisories below NPM_AUDIT_MIN_SEVERITY and deletes the temporary clone

Notes

  • The executor creates a single host per run. Its IP is 0.0.0.0 and its hostname is the name in package.json, or the directory name when there is none.
  • An advisory that affects several packages is imported only once.
  • npm audit times out after 10 minutes.
  • An unrecognized NPM_AUDIT_MIN_SEVERITY value falls back to info and is written to the agent log.
  • The shared agent parameters (AGENT_CONFIG_* tags and severity filters) are not applied by this executor. Use NPM_AUDIT_MIN_SEVERITY to filter by severity.