# 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.

Source: https://voxgig.com/howto/screen-a-new-dependency-before-merging

- Audience: platform-team
- Level: intermediate
- Languages: javascript, python
- Verified: 2026-11-29
- Published: 2026-11-29

## 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](/howto/automate-dependency-updates-with-dependabot-or-renovate). The sample uses npm;
the pnpm settings below need pnpm 10.16 or later.

## Approaches compared

| Approach | When it fits | What it costs you | When to pick something else |
| --- | --- | --- | --- |
| [deps.dev](https://docs.deps.dev/api/v3/) | You want a version's publish date, advisories and source repository from a free API | Health data rather than behavior: it had no record of the probe, and its repository links were unverified metadata | You need to know what a package does at install time |
| [OpenSSF Scorecard](https://github.com/ossf/scorecard/blob/main/docs/checks.md) | You judge whether a project is reviewed and maintained before you adopt it | Scores the repository, not the tarball, and a quiet project scores zero on Maintained | The threat is a malicious release pushed with a stolen token |
| [osv-scanner](https://google.github.io/osv-scanner/usage/scan-source) | You need known advisories for every lockfile entry, in CI | Sees published advisories only, so an unreported malicious version passes it clean | You must stop install-time behavior before anyone reports it |
| [Socket](https://docs.socket.dev/docs/socket-for-github) | You want install-script, typosquat and malware alerts as a required pull request check | An account, and its presets never block or warn on install scripts until you edit the policy | Lockfiles 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`](https://google.github.io/osv-scanner/usage/scan-source)
reads for the whole lockfile. Socket covers more behaviors, at the price of an account and a policy to edit: its
[three presets](https://docs.socket.dev/docs/enabled-issues) 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](https://docs.npmjs.com/cli/v10/using-npm/config/#ignore-scripts)
documents:

```text title=".npmrc"
ignore-scripts=true
```

pnpm 10 already skips dependency build scripts unless a package is approved. The sample adds a
seven-day [`minimumReleaseAge`](https://pnpm.io/10.x/settings#minimumreleaseage), which pnpm
added in 10.16.0, and
[`strictDepBuilds`](https://pnpm.io/10.x/settings#strictdepbuilds), so an unapproved script fails
the install instead of printing a warning:

```yaml title="pnpm-workspace.yaml"
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:

```bash
node install-demo.mjs
```

```text output
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`:

```bash
cat evidence/pnpm-builds.txt evidence/release-age.txt
```

```text output
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.

```js title="gate.mjs"
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:

```bash
node gate.mjs pr/base/package-lock.json pr/head/package-lock.json; echo "exit $?"
```

```text output
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](https://google.github.io/osv.dev/post-v1-querybatch/),
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:

```yaml title="workflow/dependency-gate.yml"
      - 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

```bash
node --test gate.test.mjs
```

```text output
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:

```bash
node gate.mjs pr/base/package-lock.json pr/probe-only/package-lock.json --checks vulnerability; echo "exit $?"
```

```text output
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`](https://docs.npmjs.com/cli/v10/commands/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:

```bash
node signals.mjs
```

```text output
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.

## Related how-tos

- [Automate dependency updates with Dependabot or Renovate](/howto/automate-dependency-updates-with-dependabot-or-renovate)

- [Generate an SBOM for a generated SDK](/howto/generate-an-sbom-for-a-generated-sdk)

- [Judge whether an unofficial SDK is safe to depend on](/howto/judge-an-unofficial-sdk-before-adoption)

- [Write a CVE response runbook for an SDK](/howto/write-a-cve-response-runbook-for-an-sdk)

- [Decide if a library should have zero runtime dependencies](/howto/decide-on-zero-runtime-dependencies)

## 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.

[^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`](https://pnpm.io/10.x/settings#minimumreleaseage), a full day,
against the hour that sentence names.

[^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`](https://docs.deps.dev/api/v3/). 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.