Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(browser): scope reviewed executable call sites [C7,O5]

Corey Olson54e1f46ca6d5
diff --git a/src/browser-admission.js b/src/browser-admission.js
index 377a8a44..5f801880 100644
--- a/src/browser-admission.js
+++ b/src/browser-admission.js
@@ -64,6 +64,24 @@ const SAFE_CHILD_PROCESS_MODULES = new Map([
['src/module-imports.js', 'runs the Node parser in an isolated child'],
['src/resources.js', 'reads process identity with /bin/ps'],
]);
+/** Reviewed generic executors and fixed Git/Node calls retain prior import behavior; all other calls stay conservative. */
+const REVIEWED_EXECUTORS = new Map([
+ ['src/cli.js', [{ function: 'sweepHere',
+ site: "spawnSync(item.check, { cwd: ctx.info.root, shell: true, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 })",
+ reason: 'sweep runs the separately selected checker; importing the CLI does not select or run it' }]],
+ ['src/sentinel-runner.js', [{ function: 'executeSentinel',
+ site: "spawn(row.check, { cwd: directory, env: environment, shell: true, stdio: ['ignore', 'pipe', 'pipe'] })",
+ reason: 'the Windows sentinel executor runs an approved check only when explicitly invoked' }]],
+ ['src/rigor-proof.js', [{ function: 'runOwnedCheck',
+ site: "spawn(runner?.executable ?? '/bin/sh', runner?.args ?? ['-c', check], { cwd: tree, env: environment, detached: true, stdio: ['ignore', 'pipe', 'pipe'] })",
+ reason: 'prepareCauseProof validates the named runner executable against the real process.execPath' }]],
+ ['test/cli-startup.test.js', [{ function: 'fixture',
+ site: "runFixtureChild(env.PULLBOARD_REAL_GIT, args, { cwd, env, encoding: 'utf8' })",
+ reason: 'this private fixture binds PULLBOARD_REAL_GIT to realGitPath before installing its counting shim' }]],
+ ['test/git-calls.test.js', [{ function: 'advanceHead',
+ site: "execFileSync(box.env.PULLBOARD_REAL_GIT, ['commit-tree', tree, '-p', parent], { cwd: box.repo, env: box.env, input: label, encoding: 'utf8' })",
+ reason: 'the private fixture binds this exact plumbing call to its realGit executable' }]],
+]);
export { literalShellWords } from './literal-shell-words.js';
@@ -246,8 +264,8 @@ function launchFreeChromeImport(source, request) {
}
/** Detect direct literal Chrome launchers without treating help text or refusal messages as launches. */
-function namesChromeLauncher(source) {
- return sourceLaunchesBrowser(source);
+function namesChromeLauncher(source, path) {
+ return sourceLaunchesBrowser(source, REVIEWED_EXECUTORS.get(path));
}
/** Detect dynamic process builtin access, which can load launch-capable modules.
@@ -541,7 +559,7 @@ async function testsNeedBrowserInTree(root, files, committed = null, onFallback,
}
}
if (!sources.length) break;
- const browserCalls = sources.map(namesChromeLauncher);
+ const browserCalls = sources.map((source, index) => namesChromeLauncher(source, paths[index]));
if (paths.some((path, index) => (path.startsWith('test/') || SAFE_CHILD_PROCESS_MODULES.has(path))
&& browserCalls[index])) return true;
// By launch, a process or module starter launches a browser only beside a Chrome executable reference.
diff --git a/src/browser-launch-source.js b/src/browser-launch-source.js
index ec63b22b..ffe5c9b9 100644
--- a/src/browser-launch-source.js
+++ b/src/browser-launch-source.js
@@ -60,6 +60,28 @@ function processNamespaces(source) {
/** Unknown member-valued executables need admission; Node's own executable identities are known. */
function unresolvedMemberCommand(expression) {
const compact = expression.replace(/\s/gu, '');
+ // A conditional's predicate is not one of the executable values it returns.
+ let nested = 0;
+ for (let at = 0; at < compact.length; at += 1) {
+ if ('([{'.includes(compact[at])) {
+ const end = closing(compact, at);
+ if (end === null) return true;
+ at = end;
+ } else if (compact[at] === '?' && !['?', '.'].includes(compact[at + 1]) && compact[at - 1] !== '?') {
+ const start = at + 1;
+ for (at = start; at < compact.length; at += 1) {
+ if ('([{'.includes(compact[at])) {
+ const end = closing(compact, at);
+ if (end === null) return true;
+ at = end;
+ } else if (compact[at] === '?' && !['?', '.'].includes(compact[at + 1]) && compact[at - 1] !== '?') nested += 1;
+ else if (compact[at] === ':' && nested-- === 0) {
+ return unresolvedMemberCommand(compact.slice(start, at)) || unresolvedMemberCommand(compact.slice(at + 1));
+ }
+ }
+ return true;
+ }
+ }
// Calls and object/template construction do not return the value of each member they read.
// In particular, a pid used to build a directory name is not an executable-valued alias.
let brackets = 0;
@@ -89,6 +111,24 @@ function expressionEnd(code, start, newlineEnds = true) {
return end;
}
+/** A reviewed exception matches one complete call inside its named function, never a whole module. */
+function reviewedCall(source, code, call, end, executors) {
+ const compact = text => text.replace(/\s/gu, '');
+ for (const executor of executors) {
+ if (compact(source.slice(call.at, end + 1)) !== compact(executor.site)) continue;
+ const pattern = new RegExp(`\\bfunction\\s+${executor.function}\\s*\\(`, 'gu');
+ for (const match of code.matchAll(pattern)) {
+ const parameters = closing(code, match.index + match[0].length - 1);
+ if (parameters === null) continue;
+ const body = parameters + 1 + code.slice(parameters + 1).search(/\S/u);
+ if (code[body] !== '{') continue;
+ const last = closing(code, body);
+ if (last !== null && call.at > body && end < last) return true;
+ }
+ }
+ return false;
+}
+
/**
* Determine whether executable process calls can reach a Chrome argument. Local literal bindings are
* followed conservatively, without scope-sensitive elimination. A program supplied to a real process
@@ -96,9 +136,10 @@ function expressionEnd(code, start, newlineEnds = true) {
* Template interpolations remain executable in lex.code. This is not an arbitrary JavaScript evaluator.
*
* @param {string} source
+ * @param {{function:string,site:string,reason:string}[]} [reviewedExecutors]
* @returns {boolean}
*/
-export function sourceLaunchesBrowser(source) {
+export function sourceLaunchesBrowser(source, reviewedExecutors = []) {
const { code, strings } = lex(source);
const names = callNames(source, code);
const namespaces = processNamespaces(source);
@@ -134,7 +175,7 @@ export function sourceLaunchesBrowser(source) {
.filter(match => names.has(match[1])).map(match => {
const before = code.slice(0, match.index).trimEnd();
const owner = /([$A-Z_a-z][$\w]*)\s*(?:\?\.|\.)$/u.exec(before)?.[1];
- return { start: match.index + match[0].length - 1,
+ return { at: match.index, start: match.index + match[0].length - 1,
unknown: !before.endsWith('.') || namespaces.has(owner) };
});
for (const namespace of namespaces) {
@@ -142,7 +183,7 @@ export function sourceLaunchesBrowser(source) {
const pattern = new RegExp(`(?<![\\w$.])${escaped}\\s*(?:\\?\\.)?\\s*\\[\\s*(['"])([$A-Z_a-z][$\\w]*)\\1\\s*\\]\\s*(?:\\?\\.)?\\s*\\(`, 'gu');
for (const match of source.matchAll(pattern)) {
if (PROCESS_CALLS.has(match[2]) && code.slice(match.index, match.index + namespace.length) === namespace) {
- calls.push({ start: match.index + match[0].length - 1, unknown: true });
+ calls.push({ at: match.index, start: match.index + match[0].length - 1, unknown: true });
}
}
}
@@ -154,7 +195,7 @@ export function sourceLaunchesBrowser(source) {
if ([...code.slice(start + 1, end).matchAll(WORD)].some(word => namedBrowser(word[0]))) return true;
// A regex's .exec is not the imported process capability. Unknown-value admission
// applies to bare process bindings and imported process namespaces, not unrelated methods.
- if (call.unknown) {
+ if (call.unknown && !reviewedCall(source, code, call, end, reviewedExecutors)) {
const commandEnd = expressionEnd(code, start + 1, false);
if (commandEnd === null) return true;
const command = code.slice(start + 1, commandEnd);
diff --git a/test/test-resources.test.js b/test/test-resources.test.js
index 520e10f1..e9554475 100644
--- a/test/test-resources.test.js
+++ b/test/test-resources.test.js
@@ -525,6 +525,39 @@ test('later executable assignments retain every possible browser launch value [C
});
/** Member commands retain their own values without tainting an unrelated local identifier. */
+test('reviewed executor imports stay browser-free only at their exact call sites [C7,O5]', async t => {
+ const repository = resolve(import.meta.dirname, '..');
+ const entries = [
+ ['src/cli.js', 'sweepHere', 'spawnSync(item.check,'],
+ ['src/sentinel-runner.js', 'executeSentinel', 'spawn(row.check,'],
+ ['src/rigor-proof.js', 'runOwnedCheck', "spawn(runner?.executable ?? '/bin/sh',"],
+ ['test/cli-startup.test.js', 'fixture', 'runFixtureChild(env.PULLBOARD_REAL_GIT,'],
+ ['test/git-calls.test.js', 'advanceHead', 'execFileSync(box.env.PULLBOARD_REAL_GIT,'],
+ ];
+ const root = sourceFixture(t, {});
+ cpSync(join(repository, 'src'), join(root, 'src'), { recursive: true });
+ cpSync(join(repository, 'test'), join(root, 'test'), { recursive: true });
+ for (const [index, [file, name, call]] of entries.entries()) {
+ const importer = `test/reviewed-executor-${index}.test.js`;
+ const request = file.startsWith('src/') ? `../${file}` : `./${file.slice(5)}`;
+ writeFileSync(join(root, importer), `import '${request}';\n`);
+ const source = readFileSync(join(root, file), 'utf8');
+ assert.ok(source.includes(`function ${name}(`) && source.includes(call), `${file}: the reviewed function and call still exist`);
+ assert.equal(await testsNeedBrowser(root, [importer], { byLaunch: true }), false,
+ `${file}: importing the reviewed executor does not execute its command`);
+ writeFileSync(join(root, file), source.replace(call, call.replace(/\([^,]+,/u, "('google-chrome',")));
+ assert.equal(await testsNeedBrowser(root, [importer], { byLaunch: true }), true,
+ `${file}: a known Chrome call remains bound inside the reviewed function`);
+ writeFileSync(join(root, file), source.replace(call, call.replace(/\([^,]+,/u, '(options.command,')));
+ assert.equal(await testsNeedBrowser(root, [importer], { byLaunch: true }), true,
+ `${file}: another unknown object command in the same function remains bound`);
+ writeFileSync(join(root, file), source + '\nexport function unreviewedCommand(options) { spawnSync(options.command, []); }\n');
+ assert.equal(await testsNeedBrowser(root, [importer], { byLaunch: true }), true,
+ `${file}: an unknown object command outside the reviewed call remains bound`);
+ writeFileSync(join(root, file), source);
+ }
+});
+
test('process member commands retain property assignments and unresolved targets [C7,O5]', async t => {
const imports = "import { spawnSync } from 'node:child_process';\n";
const root = sourceFixture(t, {
@@ -539,15 +572,19 @@ test('process member commands retain property assignments and unresolved targets
'test/fallback-command.test.js': imports + "const options = {}; options.command = 'google-chrome'; spawnSync(options.command || 'git', []);",
'test/namespace-command.test.js': "import * as child from 'node:child_process'; export function run(options) { return child.spawnSync(options.command, []); }",
'test/namespace-key-command.test.js': "import * as child from 'node:child_process'; export function run(options) { return child['spawnSync'](options.command, []); }",
+ 'test/conditional-command.test.js': imports + "export function run(options) { return spawnSync(options.enabled ? options.command : 'git', []); }",
+ 'test/conditional-data.test.js': imports + "const executable = process.platform === 'darwin' ? '/usr/sbin/lsof' : process.platform === 'linux' ? '/usr/bin/lsof' : null; spawnSync(executable, []);",
'test/property-data.test.js': imports + "const options = {}; options.command = 'google-chrome'; spawnSync('git', ['status']);",
});
for (const name of ['dot-command', 'spaced-command', 'literal-key-command', 'computed-command', 'unresolved-command',
- 'member-alias-command', 'optional-command', 'multiline-command', 'fallback-command', 'namespace-command', 'namespace-key-command']) {
+ 'member-alias-command', 'optional-command', 'multiline-command', 'fallback-command', 'namespace-command', 'namespace-key-command', 'conditional-command']) {
assert.equal(await testsNeedBrowser(root, [`test/${name}.test.js`], { byLaunch: true }), true,
`${name}: a real member command remains browser-bound`);
}
assert.equal(await testsNeedBrowser(root, ['test/property-data.test.js'], { byLaunch: true }), false,
'an unused property value does not taint a literal Git command');
+ assert.equal(await testsNeedBrowser(root, ['test/conditional-data.test.js'], { byLaunch: true }), false,
+ 'a platform predicate does not become one of the fixed executable values');
assert.equal(await testsNeedBrowser(root, ['test/property-data.test.js'], { byLaunch: false }), true,
'default admission remains conservative');
});