Don't be alarmed by vulnerabilities after NPM Install (2024)

I’ve seen more and more questions since the folks at NPM added an automatic scan for vulnerabilities after every NPM install. What’s going on? The NPM registry runs a security audit on NPM packages. With the release of NPM v6, this command is run automatically when you execute an npm install on your project. You can manually run one of these audits by executing the command npm audit (ref:npm-audit docs).

What does the audit command do? It takes the current version of a package in your project and checks the list of known vulnerabilities for that specific package & version. If it finds a vulnerability, it reports it.

What does the experience look like? Say you create a new project, like a SharePoint Framework project, using the Yeoman generator from Microsoft. The first thing the Yeoman generator does after scaffolding up the folders & files for your project is run npm install. Today, with SPFx v1.6.0, at the end of this install process, you are greeted with the following audit summary:

Don't be alarmed by vulnerabilities after NPM Install (1)

Unfortunately, this message scares a bunch of developers. People see this and have the reaction they are installing a virus or something… especially when you see there are over 100 vulnerabilities & of which, 160+ are listed as high!

Should you be alarmed? NO!

In my opinion, you should NOT be alarmed by this. In the world of reusable packages, and I’m not just referring to NPM as the exact same thing is true for all others including NuGet, packages can rely on other packages which creates a web of dependencies.

The NPM audit command is checking all dependencies, including those someone else has setup.

Let’s take a look at two of these. You can get more details on the list of issues by running npm audit. When I run that, you get a long list, but I’ll call out just two in this case. One with a moderate status and one with a high status:

Don't be alarmed by vulnerabilities after NPM Install (2)
Don't be alarmed by vulnerabilities after NPM Install (3)

There’s one thing to take notice of in both of these screenshots. Look at the Dependency Of field. Notice it says that these packages (mime & parsejson) are both referenced by one of the core Microsoft packages used by the SharePoint Framework: @microsoft/sp-build-web & @microsoft/sp-webpart-workbench.

How should you handle these audit reports?

You have a few options, but what I advise my students to do is just ignore these warnings on a new project.

Why? These are dependencies someone else has added to their package. You can’t just change the dependencies someone else has taken an expect nothing adverse to happen. Maybe things will work just fine, but does changing dependencies upstream sound like a trivial change? It shouldn’t… because it isn’t.

That is why I ignore them and suggest you do the same.

If you really want to be a good developer citizen, you should jump over to the package that takes the dependency, fork their repo, modify the dependency to remove the reference to the vulnerable package version & replace it with the “fixed” version, test to make sure everything still works, then submit a pull request (PR). Once the PR is merged in, other packages who take the dependency on that one will use the new dependency and the vulnerability will go away.

Unfortunately, that isn’t always feasible because some of these packages don’t provide the source or accept PR’s, as in the case of many of the SPFx related packages by Microsoft. And do you really have the time to do that for 200+ vulnerabilities in a brand new project? I know I don’t…

Why not just run “npm audit fix”?

You shouldn’t just blindly upgrade the projects by running npm audit fix as the report says. That will automatically upgrade the package to the fixed version. While that may be easy & sound like what you want, consider if one of those fixes included different functionality, new or deprecated features or a different API signature?

Yeah… stuff just breaks. And before you say “yeah butsemver!”, know that not everyone has adopted or follows semver. Just because one package does follow semver doesn’t mean the dependencies it takes supports or follows it.

For SPFx developers, please ignore these reports on new projects. Remember, an SPFx project is never deployed to SharePoint. These projects are just used to create the artifacts that are deployed to SharePoint (JavaScript files embedded within a SharePoint package). No NPM packages or libraries are deployed (unless you add additional packages to your project and include them in the bundle) so you should not be concerned about them.

Don't be alarmed by vulnerabilities after NPM Install (2024)

FAQs

How do I fix npm installation vulnerabilities? ›

🎉 Solution
  1. Delete your package-lock.json file or for yarn users, delete your yarn.lock file. ...
  2. So a better solution here would be to only delete the lines corresponding to the vulnerable package in your package-lock.json(or yarn.lock) file.
  3. Run npm install again.

How do you fix security vulnerabilities in npm dependencies? ›

If security vulnerabilities are found and updates are available, you can either: Run the npm audit fix subcommand to automatically install compatible updates to vulnerable dependencies. Run the recommended commands individually to install updates to vulnerable dependencies.

Can I ignore npm audit? ›

You can skip auditing at all by adding the --no-audit flag.

Is npm a security risk? ›

Many popular npm packages have been found to be vulnerable and may carry a significant risk without proper security auditing of your project's dependencies. Some examples are npm request, superagent, mongoose, and even security-related packages like jsonwebtoken, and validator.

How do you remove vulnerabilities? ›

You can fix a vulnerability by installing an operating system update, changing the application configuration, or installing an application patch. Detected vulnerabilities may apply not to installed applications but to their copies. A patch can fix a vulnerability only if the application is installed.

Are npm packages safe? ›

Malware Detection

The company claims it found more than 1,300 malicious npm packages in 2021 in npm. That's bad, but 1,300 out of 1.8-million is only 0.007222%. If you were to just randomly grab JavaScript packages for your program, odds are you'll be safe.

How do I know if a NPM package is safe? ›

How to run npm audit
  1. Go to the terminal, and on the directory of your installed package, type the following: cd path/to/name-of-package. ...
  2. Confirm that the selected package directory has a package-lock. ...
  3. Type the following command: ...
  4. Review the generated vulnerability report and take action, as appropriate.
19 Aug 2020

How can you make sure your dependencies are safe? ›

There are number of aspects you need to get right.
  1. Automate your build and deployment processes. ...
  2. Deploy known-good versions of software. ...
  3. Be careful of private dependencies. ...
  4. Use dedicated tools to scan your dependency tree for security risks. ...
  5. Keep on top of security bulletins.

What is npm security? ›

By identifying the contents of each layer of an NPM package and its dependencies, then checking whether the contents contain known security vulnerabilities, NPM security scanning helps protect both developers and end-users from malware, insecure application code and other threats that may exist within NPM packages.

What are npm vulnerabilities? ›

A vulnerability has been discovered in the NPM package ua-parser-js that could allow for remote code execution upon installation of the affected versions. NPM is the default package manager for the Javascript runtime environment Node.

How do I reinstall npm? ›

To use the official Node installer for reinstalling the tools, go to the Node. js download page and select the version you want to install—just as we described previously. Remember to choose the macOS installer option. If you run the installer, it will complete the reinstallation process for you automatically.

How do you fix a vulnerable transitive dependency? ›

Once you identify your package to be fixed using any of the above methods, to fix the transitive dependency, you must add a dependency to the updated version of the vulnerable package by adding it to the . csproj file. i.e such a vulnerable package needs to be made a direct dependency of your main project.

How do I update npm to latest version? ›

Updating local packages
  1. Navigate to the root directory of your project and ensure it contains a package.json file: cd /path/to/project.
  2. In your project root directory, run the update command: npm update.
  3. To test the update, run the outdated command. There should not be any output.

Top Articles
Latest Posts
Article information

Author: Ms. Lucile Johns

Last Updated:

Views: 5704

Rating: 4 / 5 (61 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Ms. Lucile Johns

Birthday: 1999-11-16

Address: Suite 237 56046 Walsh Coves, West Enid, VT 46557

Phone: +59115435987187

Job: Education Supervisor

Hobby: Genealogy, Stone skipping, Skydiving, Nordic skating, Couponing, Coloring, Gardening

Introduction: My name is Ms. Lucile Johns, I am a successful, friendly, friendly, homely, adventurous, handsome, delightful person who loves writing and wants to share my knowledge and understanding with you.