升级包后 npm 审计抱怨漏洞

问题描述

我安装了一个名为 bbfy@0.1.0 的 npm 包,并且在输出中 npm 说:

found 1 high severity vulnerability
  run `npm audit fix` to fix them,or `npm audit` for details

所以我运行 npm audit fix 但它说它无法修复它:

fixed 0 of 1 vulnerability in 202 scanned packages
  1 vulnerability required manual review and Could not be updated

所以我运行 npm audit 并收到此消息:

$ npm audit

                       === npm audit security report ===


                                 Manual Review
             Some vulnerabilities require your attention to resolve

          Visit https://go.npm.me/audit-guide for additional guidance


  High            Arbitrary Code Execution

  Package         underscore

  Patched in      >=1.12.1

  Dependency of   bbfy

  Path            bbfy > underscore

  More info       https://npmjs.com/advisories/1674

found 1 high severity vulnerability in 202 scanned packages
  1 vulnerability requires manual review. See the full report for details.

所以我转到引用的网页,它告诉我将 underscore 升级到“版本 1.12.1 或 1.13.0-2 或更高版本”,所以我运行以下命令:

$ npm i underscore@1.13.0-2
[snip]
+ underscore@1.13.0-2
updated 1 package and audited 202 packages in 2.726s
[snip]
found 1 high severity vulnerability
  run `npm audit fix` to fix them,or `npm audit` for details

但仍然抱怨 1 个漏洞。我检查了 npm audit 及其相同的下划线漏洞。那么我是否解决了问题?如果我没有,那出了什么问题?

解决方法

NPM 将安装一个包的多个副本,以满足依赖它的包(包括您自己的顶层项目)中冲突的版本要求。

安装了较旧的、易受攻击的 underscore 版本,因为 bbfy 软件包依赖于该较旧版本。您的 npm i 命令所做的是在您请求的更高版本中安装另一个单独的 underscore 副本。 (您可以删除那个,除非您将直接在您的项目中使用 underscore。)

由于 bbfy 已五年未更新,解决此问题的唯一方法是使用 npm shrinkwrap 覆盖依赖项。 (这可能会产生损坏的代码,但我怀疑 underscore 从 1.8 到 1.12 是否以任何有问题的方式发生了变化。)