Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

better-npm-audit

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-npm-audit

Reshape a better npm audit for the community and encourage more people to include security audits into their process

  • 4.0.0-rc.2
  • next
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
47K
increased by34.96%
Maintainers
1
Weekly downloads
 
Created
Source

Better NPM Audit

The goal of this project is to help to reshape npm audit into the way the community would like, by the community itself. Giving another option for everyone and encourage more people to do security audits.

NPM

PRs Welcome npm vulnerability GitHub issues npm bundle size Languages

Supports both NPM version 6 and 7

NPM has upgraded to version 7 in late 2020 and has breaking changes on the npm audit. The output of npm audit has significantly changed both in the human-readable and --json output styles. We have added handling so it works properly in both npm versions.

DocsLink
NPM v6 & v7 changeshttps://github.blog/2020-10-13-presenting-v7-0-0-of-the-npm-cli/
NPM v7 blog posthttps://blog.npmjs.org/post/626173315965468672/npm-v7-series-beta-release-and-semver-major
Official NPM v6 audit docshttps://docs.npmjs.com/cli/v6/commands/npm-audit
Official NPM v7 audit docshttps://docs.npmjs.com/cli/v7/commands/npm-audit
Dealing with new npm audithttps://uko.codes/dealing-with-npm-v7-audit-changes

Installation

$ npm install --save better-npm-audit

or

$ npm install -g better-npm-audit

Usage

Run global

better-npm-audit audit

Run with exceptions

Demo of table displaying the security report

Unhandled or newly reported vulnerabilities will be highlighted:

Demo of table displaying the security report

Unused exceptions will be notified:

Demo of displaying the unused exception

Add into package scripts

{
  "scripts": {
    "prepush": "npm run test && npm run audit",
    "audit": "better-npm-audit audit"
  }
}

Now you can run locally or in your CI pipeline:

npm run audit

Options

FlagShortDefaultDescription
--exclude-xExceptions or the vulnerabilities ID(s) to exclude
--level-lThe minimum audit level to validate; Same as the original --audit-level flag
--production-pSkip checking the devDependencies
--registry-rThe npm registry url to use
--scan-modules-strueScan through reported modules for .nsprc file. Note: this feature currently only support NPM v7
--debug-dDebug mode

Environment Variables

VariableDescription
NPM_CONFIG_AUDIT_LEVELUsed in setting the audit level.
Note: this will be disregard if the audit level flag is passed onto the command.

Using .nsprc file to manage exceptions

You may add a file .nsprc to your project root directory to manage the exceptions. For example:

{
  "1337": {
    "active": true,
    "notes": "Ignored since we don't use xxx method",
    "expiry": 1615462134681
  },
  "4501": {
    "active": false,
    "notes": "Ignored since we don't use xxx method"
  },
  "980": "Ignored since we don't use xxx method",
  "Note": "Any non number key will not be accepted"
}

Fields

AttributeTypeDescriptionDefaultExamples
activeBooleanIf the tool should use it for exceptiontruetrue
expiryString | NumberHuman-readable date, or milliseconds since the UNIX Epoch- '2020-01-31'
- '2020/01/31'
- '01/31/2021, 11:03:58'
- '1 March 2016 15:00'
- '1 March 2016 3:00 pm'
- '2012-01-26T13:51:50.417-07:00'
- 'Sun, 11 Jul 2021 03:03:13 GMT'
- 'Thu Jan 26 2017 11:00:00 GMT+1100 (Australian Eastern Daylight Time)'
- 327611110417
notesStringNotes related to the vulnerability.

When using a .nsprc file, a report will be displayed when it starts running:

Demo of table displaying a list of exceptions

Note: the expiry date will be styled in yellow and red color if it is detected more than one or five years ago.


Auto trust security model

If we trust a package author enough to install their package, then we also trust them to create an .nsprc file that covers all the (transitive) dependencies of that package, in the context of that package.

So if we are working on a project A, and we install a package B as a dependency, then we trust the author of B to decide whether B is affected by a vulnerability in its dependency C. I also trust the author of B to make decisions about the author of package C, so if C contains an .nsprc file with an exception about a vulnerability in its dependency, D, then we trust that exception because the author of B trusts it, and we trust him.

More generally, we can imagine a chain like this:

A -> B -> C -> D -> E -> F

where npm audit reports a vulnerability in F, but we are trusting the authors of B, C, D, and E to say whether that vulnerability is relevant in the context of their packages.

Extending the example above, then, if we have a tree like this:

A -> B -> C -> D -> E -> F
 |
  -> X -> Y -> Z -> F

then the author of package A (us), still needs to worry about a vulnerability in F due to the way it may be used by X, Y, and Z. Again, though, any of the authors of X, Y, or Z can include an .nsprc exception for the vulnerability in F, and we will trust their judgement (because we are installing X's package, and he trusts Y's code, etc.)

The auto excepted vulnerabilities will be labeled as "auto" in the report table:

Demo of excluding vulnerabilities flagged by the module maintainers

You can turn this feature off by using the flag --scan-modules=false

Special shout out to @EdwinTaylor for his effort in making this possible.

Note: This feature currently only support npm v7

Debug mode

To inspect the module .nsprc file paths and details, use --debug flag to turn on debug mode:

Debug mode showing all scan paths

Changelog

You can find the changelog here.


Special mentions

  • @IanWright for his solutions in improving the vulnerability validation for us to have the minimum-audit-level and production-mode flags.

  • @EdwinTaylor for all the bug reports and improvement suggestions.

  • @MrHus for the logging of unused exceptions from the .nsprc file and -ignore flags. Courtesy of 42 BV.



If you like this project,

Buy Me A Coffee

Keywords

FAQs

Package last updated on 05 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc