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

npm audit检测到nth-check高危漏洞,寻求修复方案

修复nth-check高危漏洞的可行方案

问题背景

执行npm audit时检测到以下高危漏洞:

Severity: high
Inefficient Regular Expression Complexity in nth-check
fix available via `npm audit fix --force`
Will install react-scripts@2.1.3, which is a breaking change
node_modules/svgo/node_modules/nth-check
  css-select  <=3.1.0
  Depends on vulnerable versions of nth-check
  node_modules/svgo/node_modules/css-select
    svgo  1.0.0 - 1.3.2
    Depends on vulnerable versions of css-select
    node_modules/svgo
      @svgr/plugin-svgo  <=5.5.0
      Depends on vulnerable versions of svgo
      node_modules/@svgr/plugin-svgo
        @svgr/webpack  4.0.0 - 5.5.0
        Depends on vulnerable versions of @svgr/plugin-svgo
        node_modules/@svgr/webpack
          react-scripts  >=2.1.4
          Depends on vulnerable versions of @svgr/webpack
          node_modules/react-scripts

执行npm ls svgr得到的依赖树显示,漏洞来自@svgr/plugin-svgo@5.5.0依赖的svgo@1.3.2,项目中同时存在安全版本svgo@2.8.0:

└─┬ react-scripts@5.0.1
  ├─┬ @svgr/webpack@5.5.0
  │ └─┬ @svgr/plugin-svgo@5.5.0
  │   └── svgo@1.3.2
  └─┬ css-minimizer-webpack-plugin@3.4.1
    └─┬ cssnano@5.1.15
      └─┬ cssnano-preset-default@5.2.14
        └─┬ postcss-svgo@5.1.0
          └── svgo@2.8.0

可行解决方案

1. 使用npm overrides锁定安全版本(推荐)

通过强制指定@svgr/plugin-svgo使用已修复漏洞的svgo@2.8.0版本,无需降级react-scripts:

  • 在项目根目录的package.json中添加以下配置:
"overrides": {
  "@svgr/plugin-svgo": {
    "svgo": "^2.8.0"
  }
}
  • 执行npm install更新依赖
  • 重新运行npm audit验证漏洞是否修复

2. 升级react-scripts到最新版本

最新版react-scripts已经依赖了修复后的@svgr相关包,彻底解决依赖链问题:

  • 执行升级命令:
npm install react-scripts@latest
  • 升级后可能需要调整项目中的配置(如webpack、babel相关)以适配新版本,但这是长期维护的最优解

3. 临时忽略漏洞(不推荐)

若暂时无法修改依赖,可临时忽略该漏洞,但存在安全风险:

  • 在package.json中添加:
"npmAuditIgnore": [
  "GHSA-rp65-9cf3-cjxr"
]
  • 此方案仅为临时过渡,不建议长期使用

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 16:05:31