The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
fix(gateguard): scan runuser command strings, build commandStrings immutably
L4XB8a933ad9d665
diff --git a/scripts/hooks/gateguard-fact-force.js b/scripts/hooks/gateguard-fact-force.jsindex 66163c5dc..9d2e98564 100644--- a/scripts/hooks/gateguard-fact-force.js+++ b/scripts/hooks/gateguard-fact-force.js@@ -390,7 +390,11 @@ const EXECUTION_PREFIXES = {setsid: {},unshare: {},busybox: {},- runuser: { valueOptions: ['-u', '--user', '-g', '--group', '-G', '--supp-group'] },+ runuser: {+ valueOptions: ['-u', '--user', '-g', '--group', '-G', '--supp-group'],+ // `runuser -c '<string>'` hands the string to a shell.+ commandStringOptions: ['-c', '--command', '--session-command'],+ },chroot: { positionals: 1 },taskset: { valueOptions: ['-c', '--cpu-list'], positionals: 1, positionalUnlessValueOption: true },};@@ -407,7 +411,7 @@ const EXECUTION_PREFIXES = {*/function stripExecutionPrefixes(tokens) {let rest = tokens;- const commandStrings = [];+ let commandStrings = [];while (rest.length > 0) {const spec = EXECUTION_PREFIXES[commandBasename(rest[0])];if (!spec) break;@@ -430,10 +434,11 @@ function stripExecutionPrefixes(tokens) {opt => token.startsWith(opt) && token.length > opt.length && (opt.length === 2 || token.charAt(opt.length) === '='));if (inline) {- commandStrings.push(token.slice(inline.length + (opt => (opt.length === 2 ? 0 : 1))(inline)));+ const payload = token.slice(inline.length + (inline.length === 2 ? 0 : 1));+ commandStrings = [...commandStrings, payload];i++;} else if (commandStringOptions.includes(token)) {- if (rest[i + 1] !== undefined) commandStrings.push(rest[i + 1]);+ if (rest[i + 1] !== undefined) commandStrings = [...commandStrings, rest[i + 1]];i += 2;} else if (valueOptions.has(token)) {i += 2;diff --git a/tests/hooks/gateguard-fact-force.test.js b/tests/hooks/gateguard-fact-force.test.jsindex 1c561cc75..035b23c03 100644--- a/tests/hooks/gateguard-fact-force.test.js+++ b/tests/hooks/gateguard-fact-force.test.js@@ -1558,6 +1558,9 @@ function runTests() {expectDestructiveDeny('env time -f "%E" psql -c "drop table users"', 'GNU time -f FORMAT + psql');expectDestructiveDeny('/usr/bin/time -o /tmp/t.log psql -c "truncate audit_log"', 'GNU time -o FILE + psql');expectDestructiveDeny(`${'env '.repeat(12)}psql -c "drop table users"`, 'twelve stacked prefixes');+ expectDestructiveDeny('runuser -u postgres -c \'psql -c "drop table users"\'', 'runuser -c command string');+ expectDestructiveDeny('runuser -u postgres --command=\'psql -c "truncate audit_log"\'', 'runuser --command= command string');+ expectDestructiveDeny('runuser -u postgres --session-command \'mysql -e "delete from sessions"\'', 'runuser --session-command');}))passed++;