You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用npm audit fix无法修复semver中等漏洞,MERN应用安装遇阻求助

解决MERN应用中semver正则拒绝服务漏洞(npm audit fix无效)

问题背景

安装MERN应用时出现以下中等风险漏洞,执行npm audit fix、npm audit fix --force均无法修复,重装simple-update-notifier也无效:

# npm audit report

semver  7.0.0 - 7.5.1
Severity: moderate
semver vulnerable to Regular Expression Denial of Service
fix available via `npm audit fix`
node_modules/nodemon/node_modules/simple-update-notifier/node_modules/semver
  simple-update-notifier  1.0.7 - 1.1.0
  Depends on vulnerable versions of semver
  node_modules/nodemon/node_modules/simple-update-notifier
    nodemon  2.0.19 - 2.0.22
    Depends on vulnerable versions of simple-update-notifier
    node_modules/nodemon

3 moderate severity vulnerabilities

解决方案

1. 升级nodemon到最新版本

漏洞根源是旧版nodemon依赖的simple-update-notifier使用了不安全的semver,升级nodemon到最新版即可解决嵌套依赖问题:

npm install nodemon@latest --save-dev

执行完成后重新运行npm audit确认漏洞是否消除。

2. 使用npm overrides强制升级semver

如果升级nodemon后问题仍存在,可通过overrides字段强制所有依赖中的semver升级到安全版本(7.5.2及以上):
在项目根目录的package.json中添加以下配置:

"overrides": {
  "semver": "^7.5.2"
}

然后执行:

npm install

再次运行npm audit验证修复效果。

3. 临时忽略开发依赖漏洞(谨慎使用)

由于nodemon是开发依赖,该漏洞仅在开发环境存在,若需快速推进项目,可仅检查生产依赖的漏洞:

npm audit --production

或执行npm audit fix --only=prod只修复生产依赖的问题,但需注意此方法未彻底解决漏洞,仅临时规避。

内容的提问来源于stack exchange,提问作者Rudraksh Laddha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 04:34:55