The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
fix: reject unsupported env split-string escapes
haelyra34a97fa898a1
diff --git a/scripts/hooks/block-no-verify.js b/scripts/hooks/block-no-verify.jsindex 4448c96ef..962dd9e74 100644--- a/scripts/hooks/block-no-verify.js+++ b/scripts/hooks/block-no-verify.js@@ -266,6 +266,23 @@ function assignmentValues(prior, operand, append, dynamic, budget) {return [...values];}+class UnsupportedEnvSplitEscape extends Error {}++function validateEnvSplitEscapes(payload, budget) {+ let quote = null;+ for (let index = 0; index < payload.length; index++) {+ budget.spend();+ const character = payload[index];+ // env -S has its own escapes. Only literal single-quoted backslashes+ // (excluding env's \\ and \' escapes) agree with the shell scanner.+ if (character === '\\' && (quote !== "'" || payload[index + 1] === '\\' || payload[index + 1] === "'")) {+ throw new UnsupportedEnvSplitEscape();+ }+ if (character === "'" && quote !== '"') quote = quote === "'" ? null : "'";+ else if (character === '"' && quote !== "'") quote = quote === '"' ? null : '"';+ }+}+// Only explicit option grammars remove wrapper operands. Unknown launchers are// opaque/conservative, never guessed from a name found among data arguments.function executableWords(words, budget, inherited = new Map(), callerValues = inherited) {@@ -373,6 +390,7 @@ function executableWords(words, budget, inherited = new Map(), callerValues = inconst payload = separated ? words[i + 1]?.value || '': flag.slice(flag.startsWith('--split-string=') ? '--split-string='.length : 2);budget.spend(payload.length + 1);+ validateEnvSplitEscapes(payload, budget);const scan = scanShell(payload, budget);// Only literal word splitting is understood here. Keep complex env// syntax opaque rather than pretending to execute it as a shell.@@ -726,6 +744,9 @@ function checkCommand(input) {}}} catch (error) {+ if (error instanceof UnsupportedEnvSplitEscape) {+ return { blocked: true, reason: 'BLOCKED: Unsupported env split-string escape; hook-bypass safety could not be established.' };+ }if (!(error instanceof RangeError)) throw error;return { blocked: true, reason: 'BLOCKED: Shell analysis work budget exceeded; hook-bypass safety could not be established.' };}diff --git a/tests/hooks/block-no-verify.test.js b/tests/hooks/block-no-verify.test.jsindex c3d3913d7..5fa21cef0 100644--- a/tests/hooks/block-no-verify.test.js+++ b/tests/hooks/block-no-verify.test.js@@ -2112,6 +2112,36 @@ for (const n of [0, 1, 2, 4]) {})) passed++; else failed++;}+const quoteSplitPayload = payload => `'${payload.replace(/'/g, `'\\''`)}'`;+const escapedSplitCases = [+ ['unquoted escaped separators', 'git\\_commit\\_--no-verify', 2],+ ['single-quoted literal separators', "'git\\_commit\\_--no-verify'", 0],+ ['double-quoted escaped separators', '"git\\_commit\\_--no-verify"', 2],+ ['mixed quoted escaped separators', 'git\\_commit\\_"--no-verify"', 2],+ ['unsupported stop escape', 'printf ok\\c ignored', 2],+ ['unsupported double-quoted stop escape', 'printf "ok\\c" ignored', 2],+ ['single-quoted stop data', "printf '%s' 'ok\\c'", 0],+ ['single-quoted separator data', "printf '%s' 'git\\_commit\\_--no-verify'", 0],+ ['single-quoted newline format', "printf '%s\\n' 'git commit --no-verify'", 0],+ ['unsupported newline escape', 'printf ok\\n', 2],+ ['unsupported tab escape', 'printf ok\\t', 2],+ ['unsupported escaped backslash', 'printf ok\\\\_', 2],+ ['unsupported single-quoted backslash escape', "printf '%s' 'ok\\\\_'", 2],+ ['unsupported single-quoted apostrophe escape', "printf '%s' 'ok\\'data'", 2],+];+for (const [name, payload, expected] of escapedSplitCases) {+ for (const option of ['-S ', '-S', '--split-string=', '--split-string ']) {+ if (test(`env escape boundary ${name}: ${option}`, () => {+ const command = 'env ' + option + quoteSplitPayload(payload);+ for (const input of [command, JSON.stringify({ tool_input: { command } })]) {+ const result = runHook(input);+ assert.strictEqual(result.code, expected, result.stderr);+ if (expected === 2) assert.match(result.stderr, /Unsupported env split-string escape/);+ }+ })) passed++; else failed++;+ }+}+console.log('─'.repeat(50));console.log(`Passed: ${passed} Failed: ${failed}`);