修复npm audit报告的漏洞。

3
我正在尝试修复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

我不确定这是否与现有的错误有关,因为警告消息明确指出它无法自动修复。
我该如何解决这些问题?
我尝试了阅读这个相似的SO帖子中的答案,但没有解决任何一个问题。我尝试安装最新的ansi-regex,但没有任何改变。
有没有办法让我确定我明确引入的依赖项(即在package.json的dependencies或devDependencies中)已经隐含地拉取了这个易受攻击的依赖项?消息中提到的包都不存在于我的package.json中。 ansi-regex在我的package-lock.json中被提及了49次 - 我需要逐个查看并手动调整版本号吗(听起来很危险)。
对于这样一个泛泛而谈(但非常具体)的问题,我很抱歉。任何帮助都将不胜感激!

你有安装 @semantic-release/npm 吗? - Luis Pais
@LuisPais 没有,我没有安装那个。 - devklick
我遇到了与我提到的包相同的问题,它依赖于npm。尝试检查您的package-lock文件中是否有“npm”,这会告诉你哪个包存在问题。至于解决方法,我还没有找到。 - Luis Pais
这个回答解决了你的问题吗?Npm install gives warnings, npm audit fix not working - 0stone0
1个回答

0

我也遇到了这个问题,发现这个答案非常有帮助。但请务必阅读评论,因为如果您的测试覆盖率不够充分,它可能会导致问题。此外,我使用shrinkwrap代替package-lock,因此我删除了我的shrinkwrap文件,而不是package-lock。

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

祝你好运!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接