演示 Node.js JSON Merge Patch REST API 中的 CVE-2026-3030 原型污染漏洞,包括一个存在漏洞的服务器及用于权限提升的漏洞利用脚本。
// server.js - Vulnerable REST API with deep merge
const express = require('express');
const app = express();
app.use(express.json());
let config = {
role: 'user',
settings: {}
};
// Insecure deep merge function (pollutable via __proto__)
function deepMerge(target, source) {
for (const key in source) {
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
if (!target[key]) target[key] = {};
deepMerge(target[key], source[key]);
} else {
target[key] = source[key];
}
}
return target;
}
app.patch('/config', (req, res) => {
deepMerge(config, req.body);
res.json(config);
});
app.get('/admin', (req, res) => {
// Check admin via a property that could be polluted
if (config.role === 'admin' || config.isAdmin) {
res.send('Welcome Admin!');
} else {
res.status(403).send('Forbidden');
}
});
app.listen(3000, () => console.log('Server on :3000'));
一个 Node.js API 使用存在漏洞的深合并函数来应用 JSON 补丁。攻击者通过将 __proto__ 作为键发送,可以污染全局对象原型,添加或覆盖诸如 isAdmin 之类的属性,从而导致权限提升。
deepMerge 函数在复制键时未检查 __proto__ 或 constructor,从而允许向 Object.prototype 注入属性。npm install express
node server.js
python exploit_prototype_pollution.py