test: pin P2 sandbox validation boundary before r5 repair
This commit is contained in:
1 parent
8d88a60297
commit
07da4cf961
3 files changed
+48
No files matched your search
@@ -14,6 +14,8 @@ test('Broker keeps the sandbox client import closure: only the listed imports, n
|
||||
assert.deepEqual([...source.matchAll(/^import .*;$/gm)].map(m => m[0]), [
|
||||
// Row 210 (#1707): createHash gives host.run events the argv, stdin and output sha256 values.
|
||||
"import { randomUUID, randomBytes, createHash } from 'node:crypto';",
|
||||
// Row 331 r5: parsing-only validation, individually mounted; no PIN or host state.
|
||||
"import { validManagementKey, proxyTiming } from '../../model-proxy/src/validation.mjs';",
|
||||
// Row 265 (#1770): pure room address parsing, mounted in RUNNER_FILES beside the broker.
|
||||
"import { parseAddress } from './address.mjs';",
|
||||
// Row 65 (#1558): bindLaunch checks a run's transcript path is absolute.
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// R5: the sandbox may load parsing helpers, never proxy PIN or host state.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import * as common from '../src/common.mjs';
|
||||
|
||||
test('validation has only the exact parsing import and no state or I/O capability', () => {
|
||||
const source = readFileSync(new URL('../src/validation.mjs', import.meta.url), 'utf8');
|
||||
assert.deepEqual([...source.matchAll(/^import .*;$/gm)].map(m => m[0]), ["import { validateHeaderValue } from 'node:http';"]);
|
||||
assert.equal((source.match(/\bimport\b/g) ?? []).length, 1);
|
||||
assert.doesNotMatch(source, /\b(?:require|process|globalThis|global|fetch|eval|Function|WebSocket|XMLHttpRequest|Buffer|URL|fs|path|PIN|config|state|env)\b/);
|
||||
assert.doesNotMatch(source, /\b(?:readFile|writeFile|open|request|createServer|connect|listen|setTimeout|setInterval)\w*\b/);
|
||||
// No namespace/default import, aliases, reexports or lazy imports can expose node:http I/O.
|
||||
assert.equal((source.match(/\bvalidateHeaderValue\b/g) ?? []).length, 2);
|
||||
assert.doesNotMatch(source, /\bexport\s+(?:\*|\{)|\bimport\s*\(/);
|
||||
});
|
||||
|
||||
test('common reexports the exact validation bindings and errors keep their identity', async () => {
|
||||
const validation = await import('../src/validation.mjs');
|
||||
for (const name of ['ProxyError', 'refuse', 'validManagementKey', 'proxyTiming']) assert.equal(common[name], validation[name], name);
|
||||
assert.throws(() => validation.refuse('fixture-refusal'), e => e instanceof common.ProxyError && e.code === 'fixture-refusal' && e.message === 'fixture-refusal');
|
||||
assert.throws(() => common.refuse('fixture-refusal'), e => e instanceof validation.ProxyError);
|
||||
});
|
||||
|
||||
test('validation retains management header parsing and timing bounds', async () => {
|
||||
const { validManagementKey, proxyTiming, ProxyError } = await import('../src/validation.mjs');
|
||||
for (const value of ['a', 'fx331-key', '!~', 'a'.repeat(4096)]) assert.equal(validManagementKey(value), true);
|
||||
for (const value of ['', 'a'.repeat(4097), 'with space', 'line\n', 'line\r', '\t', '\u007f', '\u0080', null, 7]) assert.equal(validManagementKey(value), false);
|
||||
assert.deepEqual(proxyTiming({}), {});
|
||||
assert.deepEqual(proxyTiming({ rotateGraceMinutes: 1, firstOutputSeconds: 1 }), { rotateGraceMinutes: 1, firstOutputSeconds: 1 });
|
||||
assert.deepEqual(proxyTiming({ rotateGraceMinutes: 1440, firstOutputSeconds: 3600 }), { rotateGraceMinutes: 1440, firstOutputSeconds: 3600 });
|
||||
for (const [field, max, code] of [['rotateGraceMinutes', 1440, 'proxy-rotate-grace-invalid'], ['firstOutputSeconds', 3600, 'proxy-first-output-invalid']]) {
|
||||
for (const value of [0, -1, max + 1, 1.5, '120', null]) assert.throws(() => proxyTiming({ [field]: value }), e => e instanceof ProxyError && e.code === code);
|
||||
}
|
||||
});
|
||||
@@ -53,6 +53,17 @@ test("RUNNER_FILES is exactly what the runner and the harness sources it starts
|
||||
assert.deepEqual([...seen].sort(), [...RUNNER_FILES].sort());
|
||||
});
|
||||
|
||||
test("row 331 mounts only the parsing validator and fixed marker code, never proxy state", (t) => {
|
||||
const root = scratch(t);
|
||||
const list = binds({ runDir: join(root, "run"), workspace: join(root, "ws"), adapter: join(root, "a.sh"), brokerSocket: join(root, "bus.sock") });
|
||||
for (const relative of ["packages/model-proxy/src/validation.mjs", "packages/harness/src/first-output.mjs"]) {
|
||||
const src = join(REPO, relative);
|
||||
assert.deepEqual(list.filter(b => b.src === src), [{ kind: "ro", src, why: "a repository file the runner loads" }]);
|
||||
}
|
||||
assert.deepEqual(list.filter(b => b.src?.startsWith(join(REPO, "packages/model-proxy"))).map(b => b.src), [join(REPO, "packages/model-proxy/src/validation.mjs")]);
|
||||
assert.equal(list.some(b => b.src === REPO || b.src === join(REPO, "packages/harness/src")), false);
|
||||
});
|
||||
|
||||
test("sandboxProblem names a missing bwrap and a bwrap that fails", (t) => {
|
||||
const root = scratch(t);
|
||||
assert.equal(sandboxProblem({ bwrap: join(root, "nope") }), `${join(root, "nope")} is missing`);
|
||||
|
||||
Reference in new issue
Block a user