package-tripwire

Build-time security

package-tripwire

Fail CI when dependency changes look suspicious.

npm i -D package-tripwire

What it checks

  • install-scriptNew preinstall / install / postinstall scripts (or implicit node-gyp), or scripts that changed since the previous version
  • disallowed-install-scriptPackage runs install scripts but is not listed in allowScripts when enforcement is on
  • integrity-changeSame name@version with a different integrity hash or tarball source, or a lockfile hash that doesn't match the registry
  • registry-signature-invalidRegistry tarball ECDSA signature does not verify (same rules as npm audit signatures)
  • unsigned-packageRegistry metadata has no tarball signature while the registry publishes signing keys
  • provenance-lostnpm provenance attestation was present on the previous version but missing on the new one
  • provenance-missingResolved version has no provenance attestation (--require-provenance promotes to a failure)
  • disallowed-host / disallowed-scheme / name-url-mismatchlockfile-lint style tarball URL policy (opt-in via lockfileLint)

Quick usage

CLI

package-tripwire                          # compare working-tree lockfile against HEAD
package-tripwire --base origin/main       # compare against a branch / tag / commit
package-tripwire --save-baseline .tripwire/baseline.json   # snapshot the current lockfile
package-tripwire --baseline .tripwire/baseline.json         # compare against the snapshot
package-tripwire --min-age 7d --fail-on warn --sarif tripwire.sarif --json tripwire.json

API

import { run, analyze, parseAny, createRegistry, formatSarif, lintLockfile, findDisallowedInstallScripts } from 'package-tripwire';
// const { run } = require('package-tripwire');

const result = await run({ base: 'origin/main', config: { minAge: '3d', enforceAllowScripts: true, allowScripts: ['esbuild'] } });
console.log(result.findings);

Every option is documented in the package-tripwire docs.

CI / GitHub Action

name: Dependency tripwire
on: pull_request
permissions:
  contents: read
  security-events: write   # only needed for SARIF upload
jobs:
  tripwire:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - uses: MrLouisWright/package-tripwire@v1
        with:
          min-age: 72h
          fail-on: error
          sarif: tripwire.sarif
      - if: always()
        uses: github/codeql-action/upload-sarif@v3
        with: { sarif_file: tripwire.sarif }