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

Expo项目中npm audit fix --force无法修复json5高漏洞求助

Expo项目json5高安全漏洞解决办法

Expo项目检测到json5 <1.0.2版本存在高风险原型污染漏洞,漏洞源于babel-preset-expo依赖链中的旧版json5。执行npm audit fix --force会将Expo降级到1.0.0(破坏性变更),直接安装最新json5无法解决子依赖的漏洞问题。

解决方案1:使用npm overrides强制升级子依赖

npm 8.3及以上版本支持overrides字段,可强制替换所有依赖树中的json5版本为安全版本:

  1. 在项目根目录的package.json中添加以下配置:
"overrides": {
  "json5": "^2.2.3"
}
  1. 执行npm install,npm会自动将所有依赖中的json5替换为指定的安全版本。

解决方案2:清理多余依赖

从依赖树可见存在多个extraneous(多余)依赖,执行以下命令清理:

npm prune

清理后可减少依赖树复杂度,降低潜在问题。

解决方案3:升级Expo到最新稳定版

若项目允许,升级Expo到48+版本(或最新稳定版),新版本的babel-preset-expo已更新依赖链,修复了旧版json5的依赖问题:

npx expo upgrade

升级后重新执行npm audit验证漏洞是否修复。

验证修复

执行以下命令确认所有json5版本均为安全版本:

npm ls json5

或重新执行npm audit检查漏洞状态。


原始npm审计报告

json5  <1.0.2
Severity: high
Prototype Pollution in JSON5 via Parse Method
fix available via `npm audit fix --force`
Will install expo@1.0.0, which is a breaking change
node_modules/babel-preset-expo/node_modules/json5
  find-babel-config  <=1.2.0
  Depends on vulnerable versions of json5
  node_modules/babel-preset-expo/node_modules/find-babel-config
    babel-plugin-module-resolver  2.3.0 - 4.1.0
    Depends on vulnerable versions of find-babel-config
    node_modules/babel-preset-expo/node_modules/babel-plugin-module-resolver
      babel-preset-expo  *
      Depends on vulnerable versions of babel-plugin-module-resolver
      node_modules/babel-preset-expo
        expo  >=14.0.0
        Depends on vulnerable versions of babel-preset-expo
        node_modules/expo

5 high severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

依赖树详情

├─┬ @babel/core@7.20.12
│ └── json5@2.2.3 deduped
├─┬ @expo/json-file@8.2.35 extraneous
│ └── json5@1.0.2 extraneous
├─┬ babel-plugin-module-resolver@2.5.0 invalid: "5.0.0" from the root project
│ └─┬ find-babel-config@1.2.0
│   └── json5@0.5.1
├─┬ expo-splash-screen@0.17.5 extraneous
│ └─┬ @expo/prebuild-config@5.0.7
│   └─┬ @expo/json-file@8.2.36
│     └── json5@1.0.2
├─┬ expo@47.0.13
│ ├─┬ @expo/cli@0.4.11
│ │ ├─┬ @expo/json-file@8.2.36
│ │ │ └── json5@1.0.2
│ │ ├─┬ @expo/metro-config@0.5.2
│ │ │ └─┬ @expo/json-file@8.2.36
│ │ │   └── json5@1.0.2
│ │ └─┬ @expo/package-manager@0.0.57
│ │   └─┬ @expo/json-file@8.2.36
│ │     └── json5@1.0.2
│ ├─┬ @expo/config-plugins@5.0.4
│ │ └─┬ @expo/json-file@8.2.36
│ │   └── json5@1.0.2
│ ├─┬ babel-preset-expo@9.2.2
│ │ └─┬ babel-plugin-module-resolver@4.1.0
│ │   └─┬ find-babel-config@1.2.0
│ │     └── json5@0.5.1
│ └─┬ expo-constants@14.0.2
│   └─┬ @expo/config@7.0.3
│     └─┬ @expo/json-file@8.2.36
│       └── json5@1.0.2
├─┬ find-babel-config@2.0.0
│ └── json5@2.2.3 deduped
├── json5@2.2.3
└─┬ loader-utils@2.0.4 extraneous
  └── json5@2.2.3 deduped

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 19:35:46