我有一个 nuxt 项目,我试图安装 nuxt auth 但每次安装这个包时,都会出现这个 Axios 跨站请求伪造漏洞。这是我的 package.json 文件:
{
"name": "nuxt-app",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"dependencies": {
"@mdi/font": "^7.4.47",
"@nuxtjs/auth-next": "^5.0.0-1667386184.dfbbb54",
"axios": "^1.6.8",
"nuxt": "^3.10.3",
"vue": "^3.4.21",
"vue-router": "^4.3.0"
},
"devDependencies": {
"sass": "^1.71.1",
"vite-plugin-vuetify": "^2.0.3",
"vuetify": "^3.5.9"
}
}
我在网上搜索了解决方法,发现解决这个问题的方法是安装 axios 版本 >= 1.6.0。所以我安装了最新的axios版本,但问题仍然存在。我检查了安装的版本是否高于或等于 1.6.0,并且它位于 package.json 文件中,并输入以下命令:
npm list
。我还尝试在另一台计算机上安装,并删除了 package-lock.json 和 node_modules 文件夹,然后再次安装所有依赖项,但这两种方法都不起作用。我也尝试运行命令 npm audit fix --force
但它不起作用。我错过了什么?
NPM 审计报告提到了此漏洞。
列出嵌套
axios
依赖项的正确命令是 npm list axios
。它表明 @nuxtjs/auth-next
和 @nuxtjs/axios
都依赖于 Axios 0.x:
+-- @nuxtjs/[email protected]
| +-- @nuxtjs/[email protected]
| | `-- [email protected]
| `-- [email protected]
+-- [email protected]
`-- [email protected]
`-- @nuxt/[email protected]
`-- @vue/[email protected]
`-- @vue/[email protected]
`-- @vueuse/[email protected]
`-- [email protected] deduped
目的是消除对项目
axios
的嵌套 [email protected]
依赖项。
这需要将
overrides
部分添加到 package.json:
"overrides": {
"@nuxtjs/auth-next": {
"axios": "$axios",
"@nuxtjs/axios": {
"axios": "$axios"
}
}
}
并通过删除
package-lock.json
和 node_modules
并运行 npm i
来完全重新安装依赖项。结果是npm list axios
的输出应该是:
+-- @nuxtjs/[email protected] overridden
| +-- @nuxtjs/[email protected] overridden
| | `-- [email protected] deduped <--
| `-- [email protected] deduped <--
+-- [email protected]
`-- [email protected]
`-- @nuxt/[email protected]
`-- @vue/[email protected]
`-- @vue/[email protected]
`-- @vueuse/[email protected]
`-- [email protected] deduped