Safeguard
Developer Tools•

Scan the lockfile or the built bundle for front-end vulnerabilities?

Lockfile scans see every declared package, bundle scans see what shipped. Use the lockfile first, then check the bundle for vendored or CDN code.

Safeguard Security Team
3 min read

Scan the lockfile first, because it lists every package with exact versions and runs early in CI. Add a bundle or built output check for code the lockfile does not describe, such as vendored files, copied snippets and CDN scripts. Each view finds things the other misses.

What each scan sees

Lockfile scanBuilt bundle scan
Source of truthpackage-lock.json or equivalentOutput files that users download
Exact versionsYes, recorded by the package managerOften inferred from banners or code patterns
Dev only toolsIncluded unless omittedAbsent, if tree shaking and bundling removed them
Vendored or copy pasted librariesMissedSeen if recognizable
Scripts loaded from a CDNMissedMissed unless the page is crawled
Speed and timingEarly, before a buildAfter the build

npm's lockfile records version, resolved URL and an integrity hash for each package, according to the npm docs, and it is meant to be committed so everyone installs the same tree.

Why the lockfile comes first

It is precise. A scanner reads names and versions and matches them against advisories, with no guessing. It also finds vulnerable packages that are in the dependency tree but not in the final bundle, which is useful for upgrade planning even if the exposure is lower. The npm audit command works this way: it sends your dependency descriptions to the registry and asks for known vulnerabilities, and by default it needs the lockfile.

Why the bundle still matters

Bundlers rename, concatenate and minify. A library someone dropped into a vendor folder years ago will never appear in the lockfile. A script copied from a blog post will not either. Scanning the output, or crawling a deployed page, can recognize old library signatures.

The reverse also helps. The bundle shows what actually ships, so you can see which of the vulnerable packages from the lockfile scan really reached users. See are devDependencies in your production bundle.

A layered approach

  1. Commit the lockfile and install with a lockfile enforcing command in CI.
  2. Run the dependency scan on every pull request.
  3. Add a periodic scan of a deployed page to catch vendored and CDN scripts.
  4. Keep an inventory of anything the first three do not see, see how to list every third-party script.
  5. Triage by reachability, not only by severity.

Reading results with care

A finding in a package that your code never calls is lower priority than one on a path your app uses. Reachability analysis helps separate those. Safeguard offers reachability analysis alongside SBOM and dependency scanning, and you can try a free scan at gold.safeguard.sh/scan.

Try it yourself

Click through it at your own pace, or open it full screen. Watch how findings drop when only reachable code is counted.

Quick check

Is a lockfile scan enough on its own?

Not if you vendor libraries or load CDN scripts, because those never enter the lockfile.

Does npm audit scan CDN scripts?

No. It works from your dependency tree and lockfile, so scripts loaded by URL are outside it.

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.