Safeguard
Developer Tools•

Peer and optional dependencies: who owns the vulnerability fix?

A vulnerability in a peer or optional dependency is fixed in different places than a normal one. How npm treats each, and what a maintainer should do.

Safeguard Security Team
3 min read

For a peer dependency, your user's project decides the version, so your job is to widen your range to allow the fix and tell users. For an optional dependency, you ship it only if installable and must handle its absence. Plain dependencies are the ones you own.

How npm defines each type

From the npm package.json documentation:

FieldMeaningInstalled for users?
dependenciesPackages your code needsYes
devDependenciesDevelopment tools such as test and docs frameworksNot meant for consumers
peerDependenciesCompatibility with a host tool or library, usually for plugins, without requiring it directlySince npm v7, installed by default
peerDependenciesMetaMarks a peer dependency as optionalNot installed automatically if optional
optionalDependenciesUseful but not required, installation failure does not stop the installSkipped with --omit=optional

An entry in optionalDependencies overrides a same-named entry in dependencies, so list it in only one place. The docs also say your program must handle the dependency being absent.

Who decides the version

Dependencies. Your range, resolved by the user's package manager. You own the floor.

Peer dependencies. The host project usually has the package already and chooses its version. Your range declares what you are compatible with. If an advisory affects the peer, the user needs to upgrade the package in their own project. Your role is to make sure your range allows the patched version, and to say so.

Optional dependencies. They are installed when possible. A vulnerability in one affects users who got it. Check whether your feature code is the thing that calls it.

What to do for a peer dependency advisory

  1. Check your range. If it stops users from adopting the fixed major version, widen it.
  2. Test against the fixed version in CI.
  3. Release a version that allows the fix, and note it.
  4. Tell users plainly that the upgrade is on their side, with the command.

Avoid declaring a peer range that excludes the patched version for months. That forces users to choose between your plugin and a fix.

What to do for an optional dependency advisory

  1. Decide whether your usage reaches the vulnerable code.
  2. If it does, raise the floor for that optional package and release.
  3. If not, document that and still consider bumping.
  4. Make sure the code path when it is missing still works, because users may omit it.

The dev dependency case

Dev dependencies are lower priority for published libraries because users do not install them, but they still run in your CI. See the related post on dev dependency alerts for a triage order.

Overrides do not help here

An overrides entry only applies in the root project, so it cannot fix a peer for your users. The npm docs say overrides in installed packages are ignored.

Quick check

Do peer dependencies get installed automatically?

Since npm v7, yes by default, unless they are marked optional in peerDependenciesMeta.

Can a library fix a peer dependency flaw for its users?

Only indirectly, by allowing the patched version in its range. The user's project controls the installed version.

Safeguard's dependency scanning separates direct, transitive and optional components so you can see where a finding lives. Try the free scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.