Safeguard
Developer Tools•

How do npm overrides, aliases and optional dependencies affect scans?

Overrides replace versions in the tree, aliases rename packages and optional packages may not install. Each can make a scan disagree with reality.

Safeguard Security Team
3 min read

Three npm features change what is really installed: overrides replace a package anywhere in the tree, aliases install a package under another name, and optional dependencies may be skipped. A scan of package.json alone can misreport all three. Scan the lockfile or the installed tree instead.

What each feature does

Overrides. The npm documentation says they "provide a way to replace a package in your dependency tree with another version, or another package entirely." Setting "foo": "1.0.0" pins every copy of foo in the tree to that version. Overrides are only considered in the root package.json.

Aliases. The syntax "kpg": "npm:pkg@1.0.0" installs pkg@1.0.0 under the name kpg. The folder and import name say one thing and the real package says another.

Optional dependencies. Build failures do not cause installation to fail, and installing with the omit optional setting skips them entirely. The docs say it is still your program's job to handle the absence.

What can go wrong in a scan

FeatureNaive scan mistake
Override to a fixed versionReports the old version declared by a parent package
Override to a different packageLooks up advisories for the wrong name
AliasSearches for the alias name and finds no record
Optional dependencyReports a package that never installed, or misses one that did

The lockfile records what npm resolved, including these substitutions, so a lockfile aware tool is far less likely to be wrong. This is also why an override is a legitimate way to fix a transitive vulnerability, but only if the scan confirms the result. See pinning versus ranges and its trade offs for the trade offs of pinning.

Verify an override worked

  1. Record the scan result before the change.
  2. Add the override to the root package.json and reinstall to refresh the lockfile.
  3. Run the scan against the new lockfile and confirm the finding is gone.
  4. Run your tests, since an override can break a parent package that expected the old range.
  5. Re-check after each parent update, because the override may become unnecessary or conflict.

Verify aliases are understood

Create a test project with an alias to a package version that has a known advisory. Scan it. If the tool reports nothing, it is reading the alias name and not the real one. Report that to the maker and add the alias list to your manual review.

Safeguard's dependency scanning works from resolved dependency data, and you can try a lockfile at https://gold.safeguard.sh/scan.

Quick check

Does an override in a dependency's own package.json apply?

No. The npm documentation says overrides are only considered in the root package.json of a project.

Why might a scanner miss an aliased package?

It may look up the alias name instead of the real package name, so no advisory matches.

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.