AdonisJS 任意文件写(CVE-2026-21440) 漏洞复现
AdonisJS 任意文件写(CVE-2026-21440) 漏洞复现
组件简介
AdonisJS 是一个功能完善的 Node.js 后端框架。该框架从零开始构建,重点强调开发者体验和易用性。
它是 Node.js 社区中较为少见的框架之一,内置了一整套官方的一方(first-party)功能包,帮助开发者在无需花费数百小时拼装各种 npm 包的情况下,就能完成产品的开发与交付。
影响版本
bodyparser < v10.1.2
环境搭建
GPT 梭一个简单的 web
app.js
import express from 'express'
import { MultipartFile } from '@adonisjs/bodyparser'
import { Form } from '@poppinss/multiparty'
const app = express()
app.get('/', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>File Upload</title>
<style>
body { font-family: Arial; max-width: 600px; margin: 50px auto; padding: 20px; }
form { border: 2px dashed #ccc; padding: 30px; text-align: center; }
input[type="file"] { margin: 20px 0; }
button { background: #007bff; color: white; border: none; padding: 10px 20px; cursor: pointer; }
button:hover { background: #0056b3; }
</style>
</head>
<body>
<h1>File Upload</h1>
<form action="/upload" method="POST" enctype="multipart/form-data">
<input type="file" name="file" required>
<br>
<button type="submit">Upload</button>
</form>
</body>
</html>
`)
})
app.post('/upload', (req, res) => {
const form = new Form()
form.parse(req, (err, fields, files) => {
if (err) {
return res.status(400).json({ error: err.message })
}
const uploadedFile = files.file?.[0]
if (!uploadedFile) {
return res.status(400).json({ error: 'No file uploaded' })
}
const file = new MultipartFile({
fieldName: 'file',
clientName: uploadedFile.originalFilename,
headers: uploadedFile.headers,
}, {})
file.tmpPath = uploadedFile.path
file.size = uploadedFile.size
file.move('./uploads').then(() => {
res.json({
success: true,
filename: file.fileName,
size: file.size
})
}).catch(err => {
res.status(500).json({ error: err.message })
})
})
})
app.listen(3333, () => {
console.log('Server running on http://localhost:3333')
})
package.json
{
"name": "file-upload-service",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "node app.js"
},
"dependencies": {
"@adonisjs/bodyparser": "10.1.1",
"@poppinss/multiparty": "^2.0.0",
"express": "^4.18.0"
}
}
分析过程
body_parser.spec.ts

overwrite 默认为 true name 则使用用户上传的文件名


然后使用 path.join 进行拼接 path.join 无限制 直接拼接
这里就是漏洞成因


修复方案
高版本不再使用用户提供的参数作为参数

参考
https://github.com/adonisjs/bodyparser/commit/6795c0e3fa824ae275bbd992aae60609e96f0f03
AdonisJS bodyparser<10.1.2存在路径遍历漏洞,因文件名未校验导致任意文件覆盖。
由 AI 根据全文自动生成,仅供参考,以原文为准