【问题标题】:Fixing vulnerabilities reported by npm audit修复 npm audit 报告的漏洞
【发布时间】:2022-03-04 00:29:47
【问题描述】:

我正在尝试修复 npm audit 识别的 3 个漏洞,但似乎无法使用 npm audit fix 自动解决这些漏洞。

❯ npm audit fix
npm WARN audit fix ansi-regex@5.0.0 node_modules/npm/node_modules/cli-table3/node_modules/ansi-regex
npm WARN audit fix ansi-regex@5.0.0 is a bundled dependency of
npm WARN audit fix ansi-regex@5.0.0 npm@8.5.0 at node_modules/npm
npm WARN audit fix ansi-regex@5.0.0 It cannot be fixed automatically.
npm WARN audit fix ansi-regex@5.0.0 Check for updates to the npm package.
npm WARN audit fix ansi-regex@3.0.0 node_modules/npm/node_modules/string-width/node_modules/ansi-regex
npm WARN audit fix ansi-regex@3.0.0 is a bundled dependency of
npm WARN audit fix ansi-regex@3.0.0 npm@8.5.0 at node_modules/npm
npm WARN audit fix ansi-regex@3.0.0 It cannot be fixed automatically.
npm WARN audit fix ansi-regex@3.0.0 Check for updates to the npm package.
npm WARN audit fix strip-ansi@4.0.0 node_modules/npm/node_modules/string-width/node_modules/strip-ansi
npm WARN audit fix strip-ansi@4.0.0 is a bundled dependency of
npm WARN audit fix strip-ansi@4.0.0 npm@8.5.0 at node_modules/npm
npm WARN audit fix strip-ansi@4.0.0 It cannot be fixed automatically.
npm WARN audit fix strip-ansi@4.0.0 Check for updates to the npm package.
npm WARN audit fix string-width@2.1.1 node_modules/npm/node_modules/string-width
npm WARN audit fix string-width@2.1.1 is a bundled dependency of
npm WARN audit fix string-width@2.1.1 npm@8.5.0 at node_modules/npm
npm WARN audit fix string-width@2.1.1 It cannot be fixed automatically.
npm WARN audit fix string-width@2.1.1 Check for updates to the npm package.

up to date, audited 1898 packages in 3s

185 packages are looking for funding
  run `npm fund` for details

# npm audit report

ansi-regex  >2.1.1 <5.0.1
Severity: moderate
 Inefficient Regular Expression Complexity in chalk/ansi-regex - https://github.com/advisories/GHSA-93q8-gq69-wqmw
fix available via `npm audit fix`
node_modules/npm/node_modules/cli-table3/node_modules/ansi-regex
node_modules/npm/node_modules/string-width/node_modules/ansi-regex
  strip-ansi  4.0.0 - 5.2.0
  Depends on vulnerable versions of ansi-regex
  node_modules/npm/node_modules/string-width/node_modules/strip-ansi
    string-width  2.1.0 - 4.1.0
    Depends on vulnerable versions of strip-ansi
    node_modules/npm/node_modules/string-width

3 moderate severity vulnerabilities

To address all issues, run:
  npm audit fix

我不确定这是否与 existing bug 有关,因为 WARN 消息明确指出它无法自动修复。

我该如何解决这些问题?

我已尝试查看this similar SO post 中的答案,但这并不能解决任何问题。我已经尝试安装最新的ansi-regex,但帽子没有任何区别。

我有什么方法可以识别我明确引入的依赖项(即在我的依赖项或 package.json 中的 devDependencies 中)隐含地引入了这个易受攻击的依赖项?我的 package.json 中不存在消息中提到的包。

ansi-regex 在我的 package-lock.json 中被提及 49 次 - 我是否需要筛选所有这些并手动调整版本(听起来很危险)。

对于这样一个笼统(但非常具体)的问题,我们深表歉意。任何帮助将不胜感激!

【问题讨论】:

  • 你有没有安装@semantic-release/npm?
  • @LuisPais 不,没有安装
  • 我提到的包也有同样的问题,它有 npm 作为依赖项。尝试检查你的包锁是否有“npm”,它会告诉你哪个包有问题。至于修复,我还没有找到。

标签: npm npm-audit


【解决方案1】:

我也遇到过这个问题,发现 this answer 非常有帮助。 请阅读 cmets,因为如果您没有足够全面的测试覆盖率,它可能会导致问题。另外,我使用的是 shrinkwrap 代替 package-lock,所以我删除了我的 shrinkwrap 文件,而不是 package-lock。

我已经删除了我的锁定文件,但我的关键是删除 node_modules 目录。

祝你好运!

【讨论】:

    猜你喜欢
    • 2020-02-15
    • 2020-07-05
    • 2021-08-14
    • 2021-09-06
    • 1970-01-01
    • 2019-02-07
    • 2021-12-19
    • 1970-01-01
    • 2021-09-09
    相关资源
    最近更新 更多