Dependency Vulnerability Scanning: A Practical Guide
Most of your code is dependencies. Learn how to scan them for known vulnerabilities, triage the results, and keep them patched.
By Velloreth
Why dependencies matter
A modern application is mostly third-party code. A typical Node.js project has hundreds of transitive packages, and a typical container image has hundreds of operating-system packages. Every one of them runs in your process or your image, and every one is part of your attack surface.
You are responsible for the code you ship, not only the code you write. A vulnerability in a dependency is a vulnerability in your application, and the fact that you did not write it does not change the impact.
What a scanner does
A scanner reads the manifest and the lockfile, resolves the full dependency tree, and matches each package and version against a database of advisories. It reports the affected packages, the severity, and the fixed version where one exists.
The lockfile is what makes it accurate. A manifest says ^4.17.0, which could resolve to many versions. A lockfile says exactly which version is installed, which is what the scanner needs.
The advisory database is the other half. GitHub Advisory, the OSV database, and the NVD all publish advisories, and a scanner is only as current as its source.
Scanning in the pipeline
On every pull request. A new dependency is checked before it is merged, and a change to the lockfile is checked in the same run.
name: Dependency scan
on:
pull_request:
schedule:
- cron: '0 6 * * *'
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm audit --audit-level=high
On a schedule. A new advisory can affect a dependency that has not changed, so a scan that only runs on a pull request misses it. A daily scan is the standard.
On the container image. A base image has its own packages, and a scanner for the application’s dependencies does not see them. Scan the image separately.
On the repository. GitHub’s Dependabot and the dependency review action provide the same checks with less configuration, and they open a pull request for a fix.
Triage
A scanner reports a fact, not a priority. A repository with 200 alerts is not necessarily in more danger than one with 20. The count is a measure of the dependency tree, not of the risk.
Triage by severity. A critical or high advisory in a package that handles untrusted input is the first priority. A low advisory in a development-only tool is the last.
Triage by reachability. A vulnerable function that your code never calls is a lower risk than one on a request path. Some scanners can determine reachability; where they cannot, read the advisory and check whether the affected function is used.
Triage by exposure. A package that runs in a build step is not reachable from the internet. A package that parses a request body is.
Record the decision. A vulnerability that is accepted rather than fixed should have a note with the reason and a date to revisit. An undocumented acceptance becomes a forgotten one.
Keeping dependencies current
Pin versions and commit the lockfile. A lockfile makes a build reproducible, and it is what the scanner reads. A build that resolves versions at install time can pull a different version than the one that was tested.
Update regularly, in small batches. A dependency that is a year behind is hard to update, because the changelog is long and the breaking changes are many. A dependency that is updated monthly is a small change.
Automate the update. Dependabot or Renovate opens a pull request for an available update, and the CI runs the tests. The review is then a check of the changelog rather than a manual search.
Group the updates. A pull request per dependency is a lot of noise. A grouped update for the patch versions is easier to review and merge.
Read the changelog for a major version. A major version means a breaking change, and the changelog says what it is. A blind merge of a major update is how a build breaks.
The supply chain beyond vulnerabilities
A typosquatted package. A name that is one character off a popular package, published by an attacker. Check the name and the publisher before adding a dependency.
A compromised maintainer account. A legitimate package can be updated with malicious code if the maintainer’s account is taken over. A lockfile with integrity hashes limits the damage, because a changed package fails the hash check.
A post-install script. A package can run arbitrary code at install time. A CI environment with a restricted network and no secrets limits what a malicious script can do.
A dependency with no maintenance. A package that has not been updated in years will not receive a fix. Prefer a maintained alternative, or be prepared to fork.
An SBOM. A machine-readable list of every component lets you answer “am I affected” in minutes when a new vulnerability is disclosed. Generate one in the build and store it with the release.
Common mistakes
Scanning only on a pull request. A new advisory affects code that has not changed. Scan on a schedule too.
Ignoring transitive dependencies. They run in your process and are often the vulnerable ones.
Fixing by count. Updating a package to reduce the alert count without checking the changelog can break the build or introduce a regression.
A lockfile that is not committed. The build resolves a different version than the one that was tested, and the scanner cannot see the real tree.
Auto-merging every update. A major version is a breaking change. Read the changelog.
No SBOM. When a new vulnerability is disclosed, the answer takes hours instead of minutes.
A quotable summary
Dependency scanning checks the third-party packages an application uses against a database of known vulnerabilities, and it matters because most of a modern application is third-party code. Scan on every pull request and on a schedule, because a new advisory affects code that has not changed. Triage by severity, reachability and exposure rather than by the raw count, and record an accepted risk with a date to revisit. Pin versions, commit the lockfile, update in small batches, and generate an SBOM so a new disclosure can be answered quickly.
Related reading
For the pipeline that runs the scan, see ci-cd-pipeline-basics and for the image side, dockerfile-best-practices. For the broader context, secret-management-guide and zero-trust-for-small-teams.