license-sentinel

Sentinel · security scanner

license-sentinel

A license compliance gate for npm projects, plus CycloneDX/SPDX SBOMs and a NOTICES file.

npm i -D license-sentinel

What it checks

  • Dependency sourcesnode_modules (npm, yarn and pnpm .pnpm layouts, nested and scoped packages, symlinks), package-lock.json / npm-shrinkwrap.json (v1–v3), pnpm-lock.yaml (v5, v6 and v9) and yarn.lock (v1 and Berry)…
  • License resolutionreads license, legacy license: {type} and licenses: [...], SEE LICENSE IN <file> and lockfile license fields. When there is no usable field, it identifies the LICENSE/COPYING text: MIT, MIT-0, ISC, 0BSD, BSD-2/3/4-Clause…
  • SPDX expressionsAND, OR, WITH and parentheses, with OR choosing any allowed option (the least restrictive). Deprecated ids (GPL-2.0+, GPL-3.0) and common non-SPDX spellings (Apache 2.0, MIT/Apache-2.0…
  • Policyallow and deny lists (SPDX ids, globs like GPL-*, or categories like category:permissive), the presets permissive, weak-copyleft and strong-copyleft, and a category check against the project's own license…
  • Monorepos--workspaces runs a separate audit per workspace package (npm workspaces, pnpm-workspace.yaml); --workspace-report-dir writes one JSON file per package. Hoisted installs at the repo root are supported.
  • Outputtext, JSON, SARIF 2.1.0 and Markdown reports; CycloneDX 1.6 JSON and SPDX 2.3 JSON SBOMs; CSV inventory; HTML and Markdown attribution pages; custom --template files; third-party NOTICES. --fail-on and exit codes 0/1/2.

Quick usage

CLI

npx license-sentinel                                  # audit the current project (production deps)
npx license-sentinel --preset permissive --fail-on medium
npx license-sentinel --deny "GPL-*,AGPL-*,SSPL-1.0" --include-dev
npx license-sentinel --source lockfile --registry      # no node_modules: use the lockfile + npm registry
npx license-sentinel --cyclonedx bom.cdx.json --spdx bom.spdx.json --notices THIRD_PARTY_NOTICES.txt
npx license-sentinel --omit=dev --csv licenses.csv --html attribution.html
npx license-sentinel --workspaces --workspace-report-dir reports/

API

import { audit, auditAsync, auditWorkspaces, toCycloneDX, toSPDX, toNotices, formatText, parseSpdx } from 'license-sentinel';
const { audit: auditCjs } = require('license-sentinel'); // dist/index.cjs after npm install

const report = audit('.', { preset: 'permissive', deny: ['AGPL-*'] });
console.log(formatText(report, { failOn: 'high' }));
fs.writeFileSync('bom.cdx.json', toCycloneDX(report));

const mono = auditWorkspaces('.', { includeDev: false });
const lockOnly = await auditAsync('.', { source: 'lockfile', registry: true });

Every option is documented in the license-sentinel docs.

CI / GitHub Action

permissions:
  contents: read
jobs:
  licenses:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@<sha> # v4
        with: { persist-credentials: false }
      - run: npm ci --ignore-scripts
      - uses: MrLouisWright/license-sentinel@<sha> # v1
        with:
          preset: permissive
          deny: 'AGPL-*,SSPL-1.0'
          fail-on: medium
          cyclonedx: bom.cdx.json
          notices: THIRD_PARTY_NOTICES.txt