以下是npm audit
的完整细分。
到目前为止,我们已经尝试了深度npm audit fix
,我们已经尝试了shrinkwrap和手动更改相关的版本号到GitHub建议的版本固定(6.0.1)。
npm install将包重置为5.0.1,即使手动删除,重新安装等。
npm审计的输出如下。
───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate │ Inefficient Regular Expression Complexity in │
│ │ chalk/ansi-regex │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ ansi-regex │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=5.0.1 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-sass │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ node-sass > sass-graph > yargs > string-width > strip-ansi > │
│ │ ansi-regex │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-93q8-gq69-wqmw │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate │ Inefficient Regular Expression Complexity in │
│ │ chalk/ansi-regex │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ ansi-regex │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=5.0.1 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-sass │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ node-sass > sass-graph > yargs > cliui > string-width > │
│ │ strip-ansi > ansi-regex │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-93q8-gq69-wqmw │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate │ Inefficient Regular Expression Complexity in │
│ │ chalk/ansi-regex │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ ansi-regex │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=5.0.1 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-sass │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ node-sass > sass-graph > yargs > cliui > wrap-ansi > │
│ │ string-width > strip-ansi > ansi-regex │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-93q8-gq69-wqmw │
└───────────────┴──────────────────────────────────────────────────────────────┘
我们如何正确更新这个最佳依赖来避免npm审计问题?
老实说,你最好选择不去担心这些。node-sass
大概是一个开发依赖,而不是你交付给用户的东西。您不会意外地设法包含一个导致ansi-regex低效率运行的字符串。即使你这样做了,你的服务器也不会瘫痪。这会使你的构建管道花费的时间比你想象的要长。
node-sass
(最新版本为6.0.1)的干净安装仍然会导致安装易受攻击的ansi-regex
。所以你必须搞一些特殊的恶作剧来解决问题。虽然对于在生产服务器上安装漏洞的东西来说,这些诡计可能是值得的,但在这种情况下,这样做可能意味着要花费大量的精力来为一些不存在问题的东西创建一个可能很脆弱的修复程序。
因此,我强烈建议等待下一个版本的node-sass
(将是6.0.2,6.1.0或7.0.0中的一个),并希望它解决了这个问题,如果没有,也不要太担心。
您可以在package.json
的preinstall
脚本中使用npm-force-resolutions包。来自文档:
这个包修改了包锁。Json强制安装特定版本的传递依赖(依赖的依赖)
这就是我解决这个问题的方法(在我的头撞到墙上几天之后):
Inpackage.json
:
...
"scripts": {
"preinstall": "npx npm-force-resolutions"
},
"resolutions": {
"ansi-regex": "5.0.1"
},
...
那么npm i
应该安装没有漏洞。