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 Velloreth
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:
| Question | Why |
|---|---|
| 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:
- Update to a patched version in the same major
- Update to a new major, with the migration
- Apply a workaround — disable the feature, add a validation
- Replace the package
- 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:
| Defence | What it stops |
|---|---|
| A lockfile | a silent version change |
| A review of a new dependency | a malicious package |
| A provenance check | a typosquat |
| A delay before adopting a new version | a compromised release |
| A pinned version | an unexpected update |
| A build from source | a 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.
Related reading
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.