#Why this matters
A typical web application contains far more code written by other people than by its own team. Each package brings its own vulnerabilities, its own maintainers and its own dependencies. When a flaw is published in a widely used library, attackers start scanning for it within hours, and organisations that cannot answer the question "where do we use this package, and which version?" lose days they do not have.
Dependency management is therefore a security control, not housekeeping. It has four parts: know what you ship, keep builds reproducible, detect known problems automatically and fix them on a schedule.
#Know what you ship
Direct dependencies are the packages you declare. Transitive dependencies are everything those packages pull in, and they usually outnumber the direct ones many times over. Package managers record the full resolved tree in a lockfile such as composer.lock, package-lock.json, poetry.lock or requirements.txt with pinned versions.
| Practice | Benefit |
|---|---|
| Commit the lockfile | Every developer and the build server install the same versions |
| Install from the lockfile in CI and production | No surprise upgrades at deploy time |
| Prefer integrity hashes | Detects a package that changed after it was published |
| Keep an SBOM per release | Lets you search quickly when a new advisory appears |
| Remove unused packages | Smaller attack surface and less noise |
#Detect known vulnerabilities
Most ecosystems ship an audit command that compares your lockfile with public advisories.
$ composer audit
Found 2 security vulnerability advisories affecting 1 package
$ npm audit --omit=dev
found 0 vulnerabilities
$ pip-audit -r requirements.txt
Found 1 known vulnerability in 1 packageRun these in continuous integration on every pull request and on a schedule, because new advisories appear for code that did not change. Commercial and open source SCA platforms add pull request comments, policy gates and dashboards, but the principle is identical.
#Triage an advisory
Not every finding has the same urgency. Ask four questions before deciding.
- Is the package really deployed? A development-only tool is a lower risk than a runtime library.
- Is the vulnerable code reachable? A flaw in an XML parser matters little if your application never parses untrusted XML.
- What is the impact and exploitability? Read the severity, the advisory text and whether exploitation is known to be active.
- Is a fixed version available, and what does upgrading risk? Patch releases are usually safe; major versions need testing.
Record the decision with an owner and a date. A short written reason such as "not reachable, revisit when the feature ships" is far better than silence.
# A simple internal policy, expressed as data
patch_deadlines:
critical_actively_exploited: 48h
high: 7d
medium: 30d
low: next_release
exceptions:
require: owner, reason, expiry_date#Reduce supply chain risk
- Pin versions and review upgrades in pull requests instead of accepting wildcard ranges.
- Be careful with newly published packages whose names resemble popular ones; typosquatting is a real attack path.
- Prefer maintained projects with several contributors and recent releases.
- Use a private registry or proxy for builds that need to be repeatable and auditable.
- Never run install scripts from sources you do not trust on a machine that holds credentials.
#Defending / Common mistakes
- Running
updateon production machines instead of installing from the lockfile. - Ignoring audit output because it is noisy, until a real issue is buried inside it.
- Treating severity scores as the only input and skipping reachability.
- Upgrading everything at once without tests, then reverting everything after one failure.
- Forgetting build tools, container base images and front-end packages; they are dependencies too.
- No named owner for each service, so nobody acts on the alert.
#Summary
Know your dependency tree, commit lockfiles and install from them, and audit automatically in CI and on a schedule. Triage each advisory by deployment, reachability, impact and fix availability, then patch within agreed deadlines with tests. Keep an SBOM so you can answer quickly where an affected package lives.