Skip to content

package.json security checker

Free, no sign-up Runs in your browser

Paste a package.json and find install scripts, git and URL dependencies, wildcard and unbounded version ranges and other risky settings, each with a fix.

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

How to use the package.json security checker

  1. Paste your package.json, or load the example.
  2. Read the findings, worst first: each has the line, the reason and the fix.
  3. Change the file, paste it again and check that the findings are gone.
  4. Scan the lockfile next, since it holds the versions that are really installed.

About this tool

package.json decides what code npm brings onto a machine and what it runs there. Three of its settings account for most trouble. Install scripts (preinstall, install and postinstall) run by themselves on every install. Dependencies taken from git, a URL or a folder bypass the registry and its advisories. And ranges such as * or latest accept whatever is published next, including a release pushed from a stolen maintainer account.

This checker reads the file in your browser and reports each of those, with the line concerned, why it matters and what to change. It also notes an application without "private": true, which one mistaken npm publish would upload to the public registry, and a missing engines field. Ranges are read with the same grammar npm uses, so ^1.2.3 passes and >=1.2.3 is reported as unbounded.

Read the findings as questions, not verdicts. A postinstall script that builds native code is legitimate; one you cannot explain is not. The checker is a set of rules and does not replace a review. It looks at package.json only: what is installed is decided by the lockfile, so commit it and scan it for known vulnerabilities as well.

Sources

Questions

Are postinstall scripts dangerous?

In your own package.json they are a risk you can read and judge. The larger danger is in dependencies: npm runs their install scripts too, and that is how most malicious packages run their code. Installing with --ignore-scripts, or setting ignore-scripts=true in .npmrc, turns them off.

Why is * or latest a security problem?

Because the version is chosen at install time, not by you. If a maintainer account is taken over and a bad release is published, every install without a lockfile picks it up at once. A caret range with a committed lockfile moves only when you run an update.

Is a git dependency unsafe?

Not when it points at a full commit hash, which fixes the code. A branch or a tag can be moved to different code by whoever controls the repository. Git dependencies are also invisible to vulnerability scanners, which match registry names and versions.

What does "private": true do?

It makes npm publish refuse to run for that package. For an application that is never meant to be on the registry it is a free safeguard against publishing source code, and whatever secrets sit in the folder, by accident.

Related tools