Skip to content

package-lock.json integrity checker

Free, no sign-up Runs in your browser

Check a package-lock.json for entries without an integrity hash, SHA-1-only hashes, plain HTTP downloads and packages resolved from outside the npm registry.

The file is read in your browser. It is not uploaded.

Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.

How to use the package-lock.json integrity checker

  1. Drop your package-lock.json on the page, or paste it.
  2. Read the totals: entries checked and how many have a strong hash.
  3. Go through the findings; each names the packages concerned.
  4. Fix by reinstalling the named packages with a current npm, then check again.

About this tool

Each package in a package-lock.json has two fields that protect the install. “resolved” is the URL the tarball is downloaded from. “integrity” is a hash of that tarball, and npm refuses to install a download that does not match it. Together they make an install repeatable and make tampering visible, as long as both are present, strong and point where you expect.

This checker reads the lockfile in your browser and reports entries with a download URL but no hash, entries with only a SHA-1 hash, sources fetched over http:// or git://, packages resolved from a host other than registry.npmjs.org, and git sources. Workspace links and bundled packages are left out: they are local code, or they ship inside a parent package whose hash covers them.

The finding to take most seriously is a host you do not recognize. Lockfiles are long and rarely read in review, so a pull request can change the “resolved” URL of a trusted package to an attacker’s server; this is called lockfile injection. If you use a private registry or a mirror, another host is expected. The checker is a set of rules and does not replace reading lockfile changes in review.

Sources

Questions

What is the integrity field in package-lock.json?

A hash of the package tarball in Subresource Integrity format: the algorithm, a dash and the Base64 digest, for example sha512-…. On install npm hashes what it downloaded and stops with an EINTEGRITY error when the two differ.

Why is a SHA-1 integrity hash a problem?

Researchers produced the first SHA-1 collision in 2017, and cheaper attacks have followed. A SHA-1 hash therefore no longer gives strong assurance that a file is the one that was locked. npm has written SHA-512 for years; SHA-1 entries are left over from old npm versions and disappear when the packages are reinstalled.

What is lockfile injection?

An attack in which someone with the right to propose changes edits the lockfile so that a familiar package name resolves to a tarball they control, with a matching hash. The diff looks like routine noise. Checking that every “resolved” URL points at your registry catches it.

My packages come from registry.yarnpkg.com. Is that bad?

No. That host is Yarn’s alias for the npm registry and appears when a lockfile was created from a Yarn project. It is reported so that you see every host in the file; ignore the finding when you recognize the host.

Related tools