Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(eval-bank): 评分结果走认证通道,独立解码进子进程沙箱
Greptile 指出提交代码与评测器同进程,可以自己打印一行“满分”JSON 冒充结果。改为:

- 评分器每次生成随机口令经 stdin 传给评测进程;author/result-channel.mjs 在载入任何提交代码前读走口令,并先存好写出函数和计时函数。
- 评测进程以 --frozen-intrinsics 启动;grade_impl 只接受恰好一行带本次口令的 EVAL-RESULT,提交代码自行打印、提前退出都判环境无效(已用伪造提交实测)。
- opt-cshare-compression 的独立解码子进程用 Node 权限模型,只能读运行脚本、提交目录和归档,只能写输出目录;解码结果由父进程逐字节比对原文,不再采信子进程自报的指纹。授权路径先取真实路径(macOS 临时目录在 /var -> /private/var 之后)。
- opt-device-link-delta-sync 的 Host/Client 子进程读权限从整个 author 目录收窄到各自脚本。
- bench/workload.mjs 的入口判断改用 realpath,修复经符号链接或相对路径运行时 npm run bench 无输出。
- 覆盖 v2 题库 7 题、opt v2 3 题及 opt-relay-congestion-scheduler@v1、opt-routing-cost-sim@v1;校准结果不变。
- docs/calibration-checklist.md 记下认证通道、权限沙箱和留存风险。

Assisted-by: Cindy (https://cindy.app)
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
  • Loading branch information
dashhuang committed Dec 5, 2026
commit 0c967b514489f498faca354a93b23748c6f4eea5
3 changes: 3 additions & 0 deletions docs/calibration-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
- [ ] 保护相邻正常行为,阻止禁用缓存、无限缓存、截断内容等绕过。
- [ ] 并发场景使用确定性屏障或虚拟时钟,避免靠脆弱 sleep 排名。
- [ ] 挂起用例有有界清理;环境故障单列而非默认为零。
- [ ] 评分结果走认证通道:评分器每次生成随机口令经 stdin 传给评测进程,`author/result-channel.mjs` 在载入提交代码前读走口令并保存输出函数;评测进程以 `--frozen-intrinsics` 启动,只接受恰好一行带本次口令的结果。提交代码自行打印、提前退出或改写全局对象都只会得到环境无效。
- [ ] 需要隔离执行提交代码的子进程(如独立解码、独立同步端)用 Node 权限模型(Node 22 起 `--permission`,20 为 `--experimental-permission`),只放行运行脚本、提交目录与必要输入,授权路径先取真实路径;解码结果由父进程逐字节比对原文,不信任子进程自报的通过结论。
- [ ] 留存风险写清:同进程提交代码仍可读取作者目录文件(题包本身公开,不构成泄题),调试器/inspector 类内存读取不在防护范围;对抗性排名场景需另行隔离。
- [ ] 实际运行日志、环境版本、清单与 SHA-256 留存。

## 冻结与试跑
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { takeResultChannel } from './result-channel.mjs';
import assert from 'node:assert/strict';
import path from 'node:path';
import { pathToFileURL } from 'node:url';

// Taken before any submission code loads; see result-channel.mjs.
const trusted = takeResultChannel();

const [subDir] = process.argv.slice(2);
const responsesMod = await import(pathToFileURL(path.join(subDir, 'responses.mjs')).href);
const nsMod = await import(pathToFileURL(path.join(subDir, 'namespace-tool-compat.mjs')).href);
Expand Down Expand Up @@ -570,7 +574,7 @@ await runItem('baseline_function_arg_repair', async () => {
assert.equal(restored.output[0].arguments, '{"limit":25,"cursor":"7","weight":1.5}');
}, items, errors);

console.log(JSON.stringify({
trusted.emit(({
status: 'graded',
items,
details: { errors },
Expand Down
25 changes: 18 additions & 7 deletions questions/codex-namespace-tool-collision/v1/author/grade_impl.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
"""Isolated pure-Node capability grader for codex-namespace-tool-collision."""
import pathlib, shutil, tempfile, subprocess, json, sys
import pathlib, secrets, shutil, tempfile, subprocess, json, sys

HERE = pathlib.Path(__file__).resolve().parent

RESULT_TAG = 'EVAL-RESULT '


def read_result(stdout, nonce):
"""Only the evaluator knows the per-run nonce (read from stdin before any submission code
loads), so a line printed by the submission cannot pass as the result."""
prefix = f'{RESULT_TAG}{nonce} '
found = [line[len(prefix):] for line in stdout.splitlines() if line.startswith(prefix)]
if len(found) != 1:
return {'status': 'environment_invalid', 'reason': f'expected exactly one authenticated evaluator result, got {len(found)}'}
return json.loads(found[0])


def grade(submission_root):
submission_root = pathlib.Path(submission_root).resolve()
with tempfile.TemporaryDirectory(prefix='eval-codex-ns-') as td:
tmp = pathlib.Path(td)
sub_src = tmp / 'sub_src'
shutil.copytree(submission_root / 'src', sub_src)
nonce = secrets.token_hex(16)
p = subprocess.run(
['node', str(HERE / 'evaluator.mjs'), str(sub_src)],
capture_output=True, text=True, timeout=120
['node', '--frozen-intrinsics', str(HERE / 'evaluator.mjs'), str(sub_src)],
input=nonce + '\n', capture_output=True, text=True, timeout=120
)
if p.returncode != 0:
return {'status': 'environment_invalid', 'reason': (p.stderr or p.stdout)[-2000:] or 'evaluator exited nonzero'}
lines = [line for line in p.stdout.splitlines() if line.strip()]
if not lines:
return {'status': 'environment_invalid', 'reason': 'evaluator produced no output'}
return json.loads(lines[-1])
return read_result(p.stdout, nonce)

if __name__ == '__main__':
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Trusted result channel (author side, loaded before any submission code).
*
* The grader passes a fresh random nonce on stdin. This module reads it before the evaluator
* imports the submission, captures the clock / memory / GC functions the evaluator measures
* with, and hands them out exactly once. The evaluator writes its result as the only line
* tagged with the nonce; the grader accepts exactly one such line. A submission therefore
* cannot print a result of its own, re-import this module to reuse the emitter, or patch
* `performance.now` / `process.memoryUsage` to bend measurements. Run under
* `--frozen-intrinsics` so `Math`, `JSON`, `Array.prototype` and friends cannot be patched either.
* Reading process memory through a debugger is outside this guard (see docs/versioning.md).
*/
import { readFileSync, writeSync } from 'node:fs';
import { performance } from 'node:perf_hooks';

const nonce = (() => {
if (process.stdin.isTTY) return '';
try {
return readFileSync(0, 'utf8').trim();
} catch {
return '';
}
})();
const write = writeSync;
const stringify = JSON.stringify;
const now = performance.now.bind(performance);
const memoryUsage = process.memoryUsage.bind(process);
const gc = typeof globalThis.gc === 'function' ? globalThis.gc : null;
let taken = false;

export function takeResultChannel() {
if (taken) throw new Error('result channel already taken');
taken = true;
return {
now,
memoryUsage,
gc() {
if (!gc) throw new Error('gc is not exposed');
gc();
},
emit(result) {
write(1, `EVAL-RESULT ${nonce} ${stringify(result)}\n`);
},
};
}
6 changes: 5 additions & 1 deletion questions/mcp-apps-exact-origin/v1/author/evaluator.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { takeResultChannel } from './result-channel.mjs';
import assert from 'node:assert/strict';
import path from 'node:path';
import { pathToFileURL } from 'node:url';

// Taken before any submission code loads; see result-channel.mjs.
const trusted = takeResultChannel();

const [subDir] = process.argv.slice(2);
const [appCsp, networkHosts, toolUi] = await Promise.all([
import(pathToFileURL(path.join(subDir, 'app-csp.mjs')).href),
Expand Down Expand Up @@ -326,7 +330,7 @@ const manifest_ui_invariants = check(() => {
}
}, errors, 'manifest_ui_invariants');

console.log(JSON.stringify({
trusted.emit(({
status: 'graded',
items: {
exact_loopback_http_ws,
Expand Down
25 changes: 18 additions & 7 deletions questions/mcp-apps-exact-origin/v1/author/grade_impl.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
"""Isolated pure-Node security/protocol grader for MCP Apps exact-origin validation."""
import pathlib, shutil, tempfile, subprocess, json, sys
import pathlib, secrets, shutil, tempfile, subprocess, json, sys

HERE = pathlib.Path(__file__).resolve().parent

RESULT_TAG = 'EVAL-RESULT '


def read_result(stdout, nonce):
"""Only the evaluator knows the per-run nonce (read from stdin before any submission code
loads), so a line printed by the submission cannot pass as the result."""
prefix = f'{RESULT_TAG}{nonce} '
found = [line[len(prefix):] for line in stdout.splitlines() if line.startswith(prefix)]
if len(found) != 1:
return {'status': 'environment_invalid', 'reason': f'expected exactly one authenticated evaluator result, got {len(found)}'}
return json.loads(found[0])


def grade(submission_root):
submission_root = pathlib.Path(submission_root).resolve()
with tempfile.TemporaryDirectory(prefix='eval-mcp-origin-') as td:
tmp = pathlib.Path(td)
sub_src = tmp / 'sub_src'
shutil.copytree(submission_root / 'src', sub_src)
nonce = secrets.token_hex(16)
p = subprocess.run(
['node', str(HERE / 'evaluator.mjs'), str(sub_src)],
capture_output=True, text=True, timeout=60
['node', '--frozen-intrinsics', str(HERE / 'evaluator.mjs'), str(sub_src)],
input=nonce + '\n', capture_output=True, text=True, timeout=60
)
if p.returncode != 0:
return {'status': 'environment_invalid', 'reason': (p.stderr or p.stdout)[-2000:] or 'evaluator exited nonzero'}
lines = [line for line in p.stdout.splitlines() if line.strip()]
if not lines:
return {'status': 'environment_invalid', 'reason': 'evaluator produced no output'}
return json.loads(lines[-1])
return read_result(p.stdout, nonce)

if __name__ == '__main__':
try:
Expand Down
45 changes: 45 additions & 0 deletions questions/mcp-apps-exact-origin/v1/author/result-channel.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Trusted result channel (author side, loaded before any submission code).
*
* The grader passes a fresh random nonce on stdin. This module reads it before the evaluator
* imports the submission, captures the clock / memory / GC functions the evaluator measures
* with, and hands them out exactly once. The evaluator writes its result as the only line
* tagged with the nonce; the grader accepts exactly one such line. A submission therefore
* cannot print a result of its own, re-import this module to reuse the emitter, or patch
* `performance.now` / `process.memoryUsage` to bend measurements. Run under
* `--frozen-intrinsics` so `Math`, `JSON`, `Array.prototype` and friends cannot be patched either.
* Reading process memory through a debugger is outside this guard (see docs/versioning.md).
*/
import { readFileSync, writeSync } from 'node:fs';
import { performance } from 'node:perf_hooks';

const nonce = (() => {
if (process.stdin.isTTY) return '';
try {
return readFileSync(0, 'utf8').trim();
} catch {
return '';
}
})();
const write = writeSync;
const stringify = JSON.stringify;
const now = performance.now.bind(performance);
const memoryUsage = process.memoryUsage.bind(process);
const gc = typeof globalThis.gc === 'function' ? globalThis.gc : null;
let taken = false;

export function takeResultChannel() {
if (taken) throw new Error('result channel already taken');
taken = true;
return {
now,
memoryUsage,
gc() {
if (!gc) throw new Error('gc is not exposed');
gc();
},
emit(result) {
write(1, `EVAL-RESULT ${nonce} ${stringify(result)}\n`);
},
};
}
Loading