6

下面有一个完整的细分npm audit

到目前为止,我们已经尝试npm audit fix过深入,我们尝试过收缩包装并手动将相关版本号更改为 GitHub 建议的固定版本(6.0.1)。

即使在手动删除、重新安装等之后,npm install 也会将包重置为 5.0.1。

下面是 npm audit 的输出。

     ───────────────┬──────────────────────────────────────────────────────────────┐
    │ 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 审计问题?

4

2 回答 2

8

老实说,你最好的方法是选择不担心这个。node-sass可能是开发依赖项,而不是您要发送给用户的东西。您不会意外地设法包含一个导致 ansi-regex 运行效率低下的字符串。即使您这样做了,也不会关闭您的服务器。这将使您的构建管道花费的时间比您希望的要长。

在撰写本文时,node-sass没有其他依赖项的全新安装(最新版本为 6.0.1)仍会导致ansi-regex安装易受攻击的漏洞。因此,您必须进行一些特殊的恶作剧才能解决问题。虽然这些恶作剧对于在您的生产服务器上安装漏洞可能是值得的,但在这种情况下这样做可能意味着要付出很多努力来为非问题的东西创建一个潜在的脆弱修复。

所以我强烈建议只是等待下一个版本node-sass(将是 6.0.2、6.1.0 或 7.0.0 中的一个),并希望它解决了问题,如果没有,不要太担心不。

于 2021-10-16T02:31:21.427 回答
7

您可以在. _ 从文档:preinstallpackage.json

这个包修改了 package-lock.json 来强制安装特定版本的传递依赖(dependency of dependency)

这正是为我解决了这个问题的原因(经过几天的头撞墙):

package.json

...
"scripts": {
  "preinstall": "npx npm-force-resolutions"
},
"resolutions": {
  "ansi-regex": "5.0.1"
},
...

然后npm i应该安装没有漏洞。

于 2021-10-20T08:13:13.250 回答