How-to › Release and secure packages

How to screen a dependency for supply chain risk before merging#

Gate dependency pull requests on install scripts nobody allowed and on OSV advisories, set ignore-scripts and a release-age delay, and keep an owned allowlist.

Audience
Platform team
Level
intermediate
Topic
Secure the supply chain
Languages
JavaScript and Python
Verified

Read first: Automate dependency updates with Dependabot or Renovate

A pull request adds one package, the vulnerability scan is green, and the reviewer approves. The package’s postinstall script runs on every laptop and CI runner that installs it, with the permissions of whoever typed npm install. A malicious version has no advisory until somebody reports it, so a scan that reads advisories passes it.

What you get

You will end up with a pull request check that blocks install scripts nobody has allowed and versions with published advisories, plus defaults that keep scripts off and fresh releases out. This is for you if your team reviews dependency changes by reading the diff of a lockfile.

Short answer

Gate every pull request that changes a lockfile on two checks: an install script nobody has allowlisted, and an advisory that OSV.dev lists for the added version. Set ignore-scripts=true in .npmrc and pnpm’s minimumReleaseAge so a fresh release waits. An advisory scan says nothing about a version published hours ago, so the install-script check is the one that stops it. Socket offers the behavioral alerts as a hosted service.

You will need

A repository with a lockfile version 2 or 3 package-lock.json, Node 22 or later, and a CI check that can fail a pull request. The update bot that opens these pull requests is the subject of automate dependency updates with Dependabot or Renovate. The sample uses npm; the pnpm settings below need pnpm 10.16 or later.

Approaches compared

ApproachWhen it fitsWhat it costs youWhen to pick something else
deps.devYou want a version’s publish date, advisories and source repository from a free APIHealth data rather than behavior: it had no record of the probe, and its repository links were unverified metadataYou need to know what a package does at install time
OpenSSF ScorecardYou judge whether a project is reviewed and maintained before you adopt itScores the repository, not the tarball, and a quiet project scores zero on MaintainedThe threat is a malicious release pushed with a stolen token
osv-scannerYou need known advisories for every lockfile entry, in CISees published advisories only, so an unreported malicious version passes it cleanYou must stop install-time behavior before anyone reports it
SocketYou want install-script, typosquat and malware alerts as a required pull request checkAn account, and its presets never block or warn on install scripts until you edit the policyLockfiles may not leave your network, or CI must hold no vendor token

The sample builds the cheapest pair locally: an install-script check read from the lockfile, which is one of Socket’s alerts, and an OSV.dev lookup, the database that osv-scanner scan source --lockfile reads for the whole lockfile. Socket covers more behaviors, at the price of an account and a policy to edit: its three presets set install scripts to Ignore or Monitor. Scorecard and deps.dev answer a different question, whether the project is healthy, and they say nothing about one malicious version.

Turn off install scripts and hold back fresh releases

Two defaults go in first, because they also protect installs that nobody reviewed. The sample’s .npmrc turns off lifecycle scripts for npm, which the npm 10 ignore-scripts setting documents:

ignore-scripts=true

pnpm 10 already skips dependency build scripts unless a package is approved. The sample adds a seven-day minimumReleaseAge, which pnpm added in 10.16.0, and strictDepBuilds, so an unapproved script fails the install instead of printing a warning:

minimumReleaseAge: 10080
strictDepBuilds: true

install-demo.mjs installs the probe package offline into two throwaway projects. Its postinstall writes one file inside its own directory and nothing else:

node install-demo.mjs
npm 10, offline install of demo-postinstall-probe-1.0.0.tgz
the sample .npmrc      postinstall ran: no   lockfile hasInstallScript: true
  then npm rebuild     postinstall ran: yes
ignore-scripts=false   postinstall ran: yes  lockfile hasInstallScript: true

The lockfile still records hasInstallScript with scripts off, which is what the gate below reads. record.sh ran pnpm 10.28.0 on the same probe and on @types/node@^24:

cat evidence/pnpm-builds.txt evidence/release-age.txt
pnpm 10.28.0
pnpm add ./demo-postinstall-probe-1.0.0.tgz, default build policy: exit 0
  warning, ignored build scripts: demo-postinstall-probe@file:demo-postinstall-probe-1.0.0.tgz
  marker: absent
pnpm add ./demo-postinstall-probe-1.0.0.tgz, strict build policy: exit 1
  ERR_PNPM_IGNORED_BUILDS, ignored build scripts: demo-postinstall-probe@file:demo-postinstall-probe-1.0.0.tgz
  marker: absent
minimumReleaseAge 0: @types/node 24.19.4
minimumReleaseAge 10080: @types/node 24.19.2
published 24.19.2 2026-10-09
published 24.19.3 2026-11-25
published 24.19.4 2026-11-25

With the delay set, pnpm skipped two releases published four days before the run and resolved the one from October.1

Block install scripts nobody has allowed

gate.mjs compares the base and head lockfiles and screens every package whose install path is added or whose version moved. An install script blocks the merge unless allowlist.json names that exact version with an owner and a reason. A package missing from the advisory record also blocks, because an unchecked package is not a clean one.

export function screen(list, { allow, advisories, checks = CHECKS }) {
  for (const c of checks) if (!CHECKS.includes(c)) throw new Error(`unknown check ${c}`)
  const blocked = []
  const allowed = []
  for (const pkg of list) {
    const id = `${pkg.name}@${pkg.version}`
    if (checks.includes('behavior') && pkg.installScript) {
      const entry = allow.get(id)
      if (entry) allowed.push(`${id}: install script allowed by ${entry.owner} (${entry.reason})`)
      else blocked.push(`${id}: runs an install script and is not on the allowlist`)
    }
    if (checks.includes('vulnerability')) {
      if (!Object.hasOwn(advisories.results, id)) {
        blocked.push(`${id}: no vulnerability record, so it was never checked`)
      } else {
        for (const a of advisories.results[id]) {
          const aka = a.aliases.length ? ` (${a.aliases.join(', ')})` : ''
          blocked.push(`${id}: ${a.id}${aka} ${a.summary}`)
        }
      }
    }
  }
  return { blocked, allowed }
}

The sample pull request bumps ms and adds esbuild, minimist 1.2.5 and the probe. esbuild brings 26 optional platform packages, so 30 entries change:

node gate.mjs pr/base/package-lock.json pr/head/package-lock.json; echo "exit $?"
checks: behavior, vulnerability
changed packages: 30 (29 added, 1 bumped)
  allowed  esbuild@0.28.2: install script allowed by platform-team (postinstall checks the platform binary; the package also works with scripts off)
  BLOCKED  demo-postinstall-probe@1.0.0: runs an install script and is not on the allowlist
  BLOCKED  minimist@1.2.5: GHSA-xvch-5gv4-984h (CVE-2021-44906) Prototype Pollution in minimist
result: block the merge
exit 1

The advisory came from the OSV.dev querybatch endpoint, which osv-query.mjs calls for every changed package. record.sh ran it for the sample, and the workflow runs it for a real pull request.

Run both checks on every pull request

workflow/dependency-gate.yml reads the base branch’s lockfile with git show, asks OSV, then runs the gate. The base branch name goes through an environment variable rather than into the script text:

      - name: Read the lockfile on the base branch
        env:
          BASE_REF: ${{ github.base_ref }}
        run: git show "origin/$BASE_REF:package-lock.json" > "$RUNNER_TEMP/base-lock.json"
      - name: Ask OSV about every added or bumped package
        run: node tools/dependency-gate/osv-query.mjs "$RUNNER_TEMP/base-lock.json" package-lock.json "$RUNNER_TEMP/osv.json"

Make the job a required check in the branch rules, or a red run blocks nothing.

Check it worked

node --test gate.test.mjs
1..10
# tests 10
# suites 0
# pass 10
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 1281.35332

The tests pin the two blocked lines shown earlier and the exit codes 1, 0 and 2. They prove that a bump of an allowlisted package is screened again, that an allowlist entry without an owner is refused, and that the committed .npmrc stops the probe’s script. A pull request that only removes a package makes no OSV request and passes.

When it goes wrong

The advisory check passes a package that runs code at install. This is the pitfall the gate exists for. OSV had no entry for the probe, as for any malicious version nobody has reported. Run the vulnerability check alone and the probe merges:

node gate.mjs pr/base/package-lock.json pr/probe-only/package-lock.json --checks vulnerability; echo "exit $?"
checks: vulnerability
changed packages: 1 (1 added, 0 bumped)
result: pass
exit 0

The same pull request with both checks exits 1. Keep the behavioral check even when the advisory feed is clean.

A package breaks with scripts off. Some packages need their script, such as a native module compiled at install. Allowlist the exact version with an owner, then run npm rebuild for that package with --ignore-scripts=false, as install-demo.mjs does. esbuild 0.28.2 did not need its script: record.sh installed it with --ignore-scripts and its transformSync returned "let n = 1;\n".

The allowlist grows until nobody reads it. Each entry pins one version, so every bump of a scripted package comes back for review. That is the cost of the check, and the owner field says whose queue it lands in.

When not to do this

Do not treat a Scorecard number as a safety verdict. The recorded esbuild repository scored 3.8, with zero on Maintained because the scan found no commit and no issue activity in 90 days. minimist 1.2.5, the version with the advisory, mapped to a repository that scored 4.6 in 2022.2 Both numbers describe project health, not what a version does:

node signals.mjs
recorded 2026-11-29
demo-postinstall-probe@1.0.0: deps.dev has no record
esbuild@0.28.2: published 2026-08-08, advisories 0, repo github.com/evanw/esbuild, Scorecard 3.8 (scan 2026-11-23), Maintained 0
minimist@1.2.5: published 2020-03-12, advisories 1, repo github.com/substack/minimist, Scorecard 4.6 (scan 2022-09-05), Maintained 0
ms@2.1.3: published 2020-12-08, advisories 0, repo github.com/vercel/ms, Scorecard 5 (scan 2026-11-23), Maintained 0

Do not build this gate if your organization already pays for Socket. Its install-script, typosquat and malware alerts cover more behaviors than one lockfile flag, and a policy edit replaces this code. Skip the local allowlist too when every dependency goes through an internal registry that already quarantines fresh releases. The gate reads npm lockfiles only, so a Python service needs osv-scanner and its own install-time policy.

Last verified

Verified 2026-11-29 against Node 22.23.5, npm 10.9.9, pnpm 10.28.0 and esbuild 0.28.2. OSV.dev, deps.dev and the Scorecard API were queried once by record.sh, and the captured commands read that record. The workflow file was not run on GitHub Actions. Socket was not run because it needs an account; its presets and pull request check are described from its documentation. osv-scanner was not run either, and its scan source --lockfile command is quoted from its documentation.

Footnotes

  1. pnpm’s documentation gives the reasoning in one sentence: in most cases, malicious releases are discovered and removed from the registry within an hour. Its example then sets minimumReleaseAge: 1440, a full day, against the hour that sentence names. ↩︎ Back to text

  2. deps.dev links minimist 1.2.5 to github.com/substack/minimist, the repository named in that version’s own metadata, and marks the link UNVERIFIED_METADATA. The Scorecard API’s scan of that address is dated 2022-09-05, so the 4.6 describes a repository as it stood more than four years before the record was taken. ↩︎ Back to text

Read this page as markdown · All how-to guides

Generate the client instead of writing it#

Retries, timeouts, pagination and auth are the same problems in every client. Voxgig generates them from your OpenAPI description, in 23 languages, from one model.

Listen to Fireside, the Voxgig podcast

Since 2018, Richard Rodger has talked with developer advocates, event organizers, and the people who build developer-facing companies about the specifics of the work.