Skip to content

About

Check whether your npm package is ready for npm v12 security defaults. Zero dependencies.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

npm-posture

Check whether your npm package is ready for npm v12 — before your users find out the hard way.

Zero dependencies. No network calls. One command.

npx npm-posture .

Why?

npm v12 turned on new install-time security defaults:

  • allowScripts is off — preinstall/install/postinstall no longer run automatically.
  • --allow-git=none — git dependencies are not resolved by default.
  • --allow-remote=none — tarball URLs are not resolved by default.

On top of that, publishing now requires 2FA or a granular token, and bypass-2FA tokens lose direct publishing in January 2027.

npm-posture reads your package.json, lockfile and .npmrc and tells you exactly which parts of your package will behave differently under these rules — with a copy-paste fix for each finding.

$ npm-posture .

npm-posture: /path/to/my-package

[ERROR] Auth token in local .npmrc
         A registry token in the repo directory can be committed by accident.
         fix: Remove the token from .npmrc and use a user-level ~/.npmrc instead.

[WARN ] Lifecycle script "postinstall"
         npm v12 defaults allowScripts to off, so this script will not run unless the user opts in.
         fix: Avoid install scripts, or document: npm approve-scripts --allow-scripts-pending

[WARN ] Lockfile version drift
         package.json is 1.1.0, lockfile is 1.0.0.
         fix: Run npm install to update the lockfile.

Summary: 1 error(s), 2 warning(s), 1 info.

Install

npx npm-posture .
# or
npm install -g npm-posture
npm-posture .

Requires Node 18+.

Usage

npm-posture [path] [options]
Option Description
--json Emit structured findings for CI or scripts
--strict Exit non-zero on warnings too (default: only errors)
-v, --version Print version
-h, --help Show help

What it checks

Check Severity Why it matters
Missing name / version error npm will not accept the package
Auth token in local .npmrc error High risk of committing a credential
bin entry pointing to a missing file error npx fails after install
Missing description, license, repository, engines.node warn Discoverability, licensing, compatibility
Lifecycle scripts warn Silently skipped under npm v12 defaults
Git / remote URL dependencies warn Blocked by --allow-git=none / --allow-remote=none
Lockfile drift or missing lockfile warn / info Reproducibility
Scoped package without publishConfig.access warn Defaults to restricted, breaking public npx
No files field or .npmignore info Everything not git-ignored gets published

Use in CI

- run: npx npm-posture . --strict

--strict makes warnings fail the job, so a new install script or remote dependency cannot slip in unnoticed.

JSON output

npm-posture . --json > posture.json
{
  "root": "/path/to/package",
  "summary": { "errors": 1, "warnings": 2, "info": 1 },
  "findings": [
    {
      "id": "lifecycle-postinstall",
      "severity": "warn",
      "title": "Lifecycle script \"postinstall\"",
      "detail": "npm v12 defaults allowScripts to off...",
      "fix": "Avoid install scripts, or document: npm approve-scripts --allow-scripts-pending"
    }
  ]
}

Use as a library

import { checkProject } from 'npm-posture';
import { formatReport } from 'npm-posture/cli';

const result = checkProject('.');
console.log(formatReport(result));

What it does not do

  • It never installs, executes or imports your package's code.
  • It never contacts the npm registry or any other network service.
  • It cannot inspect your npm account settings (2FA, token permissions) — those live on npmjs.com.

Roadmap

  • Check CI workflows for deprecated publish patterns
  • npm-posture fix to apply safe fixes automatically
  • --baseline to ignore known findings and fail only on new ones
  • SARIF output for GitHub code scanning

License

MIT © npm-posture contributors

About

Check whether your npm package is ready for npm v12 security defaults. Zero dependencies.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages