Skip to content
Velloreth
Cybersecurity 5 min read

Dependency Vulnerabilities: Finding and Fixing Them

Most of your code is a dependency. Learn how to scan, how to triage, and how to fix a vulnerability without breaking the build.

By

Why it matters

Most of an application is a dependency. A typical project has hundreds of transitive packages.

A flaw in a transitive dependency is still your flaw. The attacker does not care which package introduced it.

The volume is the problem. A large tree produces a continuous stream of advisories.

Scanning

The package manager’s audit.

npm audit
pip-audit
cargo audit

A dedicated scanner.

trivy fs .

The repository alerts. Dependabot or a similar service opens a pull request for a known advisory.

The pipeline. Run the scan on every build, so a new advisory is caught on the next run rather than at the next audit.

The lockfile is required. A scan of a manifest without a lockfile reports the ranges, not the versions that are installed.

Triage

The severity score is an input, not the decision.

Ask:

QuestionWhy
Is the vulnerable code reachable?an unreachable path is not exploitable
What is the attack condition?a condition you do not have is not a risk
Is it production or development?a dev tool is a lower priority
Is the endpoint public?a public path is a higher priority
Is there a fix?a fix changes the plan

A high severity in an unreachable path is a lower priority than a medium severity on a public endpoint.

Record the decision. A finding that is accepted rather than fixed should have a reason and a review date.

Fixing

The order of preference:

  1. Update to a patched version in the same major
  2. Update to a new major, with the migration
  3. Apply a workaround — disable the feature, add a validation
  4. Replace the package
  5. Accept the risk, with a record and a review date

A patch in the same major is the common case, and it is usually a one-line change.

A transitive dependency is fixed by an override or a resolution.

{
  "overrides": {
    "vulnerable-package": "^2.1.3"
  }
}

The override is a temporary measure. It should be removed when the parent package updates.

The automated update

An automated update is the only sustainable fix.

The pattern:

  • A weekly pull request for the patch and minor updates
  • A separate, manual review for a major update
  • The test suite as the gate
  • A merge when the tests pass

The alternative is a manual audit every few months, which produces a large batch of updates that is risky to apply at once.

A small, frequent update is safer than a large, rare one.

Reducing the surface

A dependency you do not need is a vulnerability you do not have.

The practices:

  • Prefer the standard library
  • Prefer a small package over a framework
  • Remove a dependency that is used once
  • Check the maintenance history before adding one
  • Check the install scripts, which can run arbitrary code

A dependency review at the point of addition is cheaper than a remediation later.

The supply chain

An attack that compromises a package rather than your code.

The defences:

DefenceWhat it stops
A lockfilea silent version change
A review of a new dependencya malicious package
A provenance checka typosquat
A delay before adopting a new versiona compromised release
A pinned versionan unexpected update
A build from sourcea tampered binary

A typosquat is a package with a name close to a popular one. Check the name character by character.

A brand new version of a popular package is the highest-risk moment, because a compromise is most likely to be caught in the first days.

A remediation plan

A vulnerability backlog is best handled as a routine rather than a project. The first step is to enable the automated alerts, so a new advisory arrives as a pull request rather than as a surprise. The second is to set a policy: a critical finding is fixed within days, a high within weeks, and a medium at the next update cycle. The third is to schedule a weekly window for the updates, so the work is predictable. The fourth is to keep the test suite fast, because a slow suite is the reason an update is deferred. The fifth is to record the accepted risks with a review date, so a decision is revisited rather than forgotten. A team that follows that routine has a small, steady stream of updates, and a team that does not has a large, risky batch every few months.

Common mistakes

No scan. A known flaw ships.

A scan without a lockfile. The result is not the installed version.

Triage by severity alone. An unreachable high is treated as urgent.

No record of an accepted risk. The decision is lost.

A manual audit every few months. A large, risky batch.

An override left forever. A hidden version conflict.

A dependency added without a review. A supply chain risk.

A dev dependency treated as production. The priority is wrong.

No test suite. The update cannot be applied safely.

A quotable summary

A dependency vulnerability is a known flaw in a package your project uses, directly or transitively, and a flaw in a transitive dependency is still your flaw. Scan with the package manager’s audit or a dedicated scanner on every build, triage by reachability and attack condition rather than by the severity score alone, and fix by updating to a patched version in the same major. An automated weekly update is the only sustainable fix, and a dependency you do not need is a vulnerability you do not have.

For the related topics, see dependency-vulnerability-scanning and zero-trust-for-small-teams. For the broader context, security-headers-guide and content-security-policy-guide.

Frequently asked questions

What is a dependency vulnerability?
It is a known flaw in a package your project uses, directly or through another package. It is recorded in an advisory database with an identifier such as CVE or GHSA, and a scanner compares your lockfile against that database. A flaw in a transitive dependency is still a flaw in your application.
How do I scan for vulnerabilities?
Run the audit command of your package manager, such as npm audit, or a dedicated scanner such as Dependabot, Snyk or Trivy. Run it in the pipeline so a new advisory is caught on the next build, and enable the automated alerts on the repository.
How do I triage a finding?
Ask whether the vulnerable code is reachable from your application, whether the attack requires a condition you do not have, and whether the package is in a production path or only a development tool. A high severity in an unreachable code path is a lower priority than a medium severity on a public endpoint.
What if the fix requires a breaking change?
Check whether a patch exists in the same major version, which is the common case. If not, look for a workaround such as disabling the feature, adding a validation, or replacing the package. If none exists, record the risk, set a review date, and monitor the advisory.
How do I prevent a vulnerable dependency?
Keep the dependency count low, prefer a package with a maintained history, enable the automated updates, and pin the versions with a lockfile. A dependency you do not need is a vulnerability you do not have, and the smallest dependency tree is the easiest to keep clean.
What is a supply chain attack?
An attack that compromises a package rather than your code, so the malicious code arrives through an update. The defences are a lockfile, a review of a new dependency, a check of the package's provenance, and a delay before adopting a brand new version.