🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(guard): scan a backtick substitution as a nested command instead of ending the rm being parsed (#3791)
Dragan Spiridonov54d49ea898e1
diff --git a/.claude/helpers/hook-handler.cjs b/.claude/helpers/hook-handler.cjsindex 9d598dcc44..953071aaca 100755--- a/.claude/helpers/hook-handler.cjs+++ b/.claude/helpers/hook-handler.cjs@@ -536,6 +536,15 @@ const handlers = {if (char === '\\' && i + 1 < command.length) {const next = command[++i]if (next !== '\n') { word += next; started = true }+ } else if (char === '\x60') {+ // Command substitution: scan the body as its own command; the substitution+ // stays inside the enclosing word, so the rm being parsed keeps its state.+ let body = ''+ for (i++; i < command.length && command[i] !== '\x60'; i++) {+ if (command[i] === '\\' && i + 1 < command.length) i+++ body += command[i]+ }+ if (depth < 4 ? hasRootDelete(body, depth + 1) : body.includes('rm -rf /')) return true} else if (char === '$' && (command[i + 1] === "'" || command[i + 1] === '"')) {// ANSI-C ($'...') and locale ($"...") quoting: the $ is not part of the word.} else if (char === '"' || char === "'") {@@ -544,11 +553,11 @@ const handlers = {while (i < command.length && command[i] !== '\n') i++if (finishCommand()) return true} else if (char === ' ' || char === '\t' || char === '\r' || char === '\n' ||- ';|&()<>\x60'.includes(char)) {+ ';|&()<>'.includes(char)) {if (finishWord()) return true// Redirections separate words, but later operands still belong to rm.redirect = char === '<' || char === '>'- if (!redirectionAmpersand && (char === '\n' || ';|&()\x60'.includes(char)) && finishCommand()) return true+ if (!redirectionAmpersand && (char === '\n' || ';|&()'.includes(char)) && finishCommand()) return true} else {word += char; started = true}diff --git a/plugins/ruflo-mods/hooks/guard/dangerous-command.ts b/plugins/ruflo-mods/hooks/guard/dangerous-command.tsindex 9b6a1b843a..0acb7cd90c 100644--- a/plugins/ruflo-mods/hooks/guard/dangerous-command.ts+++ b/plugins/ruflo-mods/hooks/guard/dangerous-command.ts@@ -61,6 +61,15 @@ function hasRootDelete(command: string, depth = 0): boolean {if (char === '\\' && i + 1 < command.length) {const next = command[++i]if (next !== '\n') { word += next; started = true }+ } else if (char === '\x60') {+ // Command substitution: scan the body as its own command; the substitution+ // stays inside the enclosing word, so the rm being parsed keeps its state.+ let body = ''+ for (i++; i < command.length && command[i] !== '\x60'; i++) {+ if (command[i] === '\\' && i + 1 < command.length) i+++ body += command[i]+ }+ if (depth < 4 ? hasRootDelete(body, depth + 1) : body.includes('rm -rf /')) return true} else if (char === '$' && (command[i + 1] === "'" || command[i + 1] === '"')) {// ANSI-C ($'...') and locale ($"...") quoting: the $ is not part of the word.} else if (char === '"' || char === "'") {@@ -69,11 +78,11 @@ function hasRootDelete(command: string, depth = 0): boolean {while (i < command.length && command[i] !== '\n') i++if (finishCommand()) return true} else if (char === ' ' || char === '\t' || char === '\r' || char === '\n' ||- ';|&()<>\x60'.includes(char)) {+ ';|&()<>'.includes(char)) {if (finishWord()) return true// Redirections separate words, but later operands still belong to rm.redirect = char === '<' || char === '>'- if (!redirectionAmpersand && (char === '\n' || ';|&()\x60'.includes(char)) && finishCommand()) return true+ if (!redirectionAmpersand && (char === '\n' || ';|&()'.includes(char)) && finishCommand()) return true} else {word += char; started = true}diff --git a/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs b/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjsindex 9d598dcc44..953071aaca 100755--- a/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs+++ b/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs@@ -536,6 +536,15 @@ const handlers = {if (char === '\\' && i + 1 < command.length) {const next = command[++i]if (next !== '\n') { word += next; started = true }+ } else if (char === '\x60') {+ // Command substitution: scan the body as its own command; the substitution+ // stays inside the enclosing word, so the rm being parsed keeps its state.+ let body = ''+ for (i++; i < command.length && command[i] !== '\x60'; i++) {+ if (command[i] === '\\' && i + 1 < command.length) i+++ body += command[i]+ }+ if (depth < 4 ? hasRootDelete(body, depth + 1) : body.includes('rm -rf /')) return true} else if (char === '$' && (command[i + 1] === "'" || command[i + 1] === '"')) {// ANSI-C ($'...') and locale ($"...") quoting: the $ is not part of the word.} else if (char === '"' || char === "'") {@@ -544,11 +553,11 @@ const handlers = {while (i < command.length && command[i] !== '\n') i++if (finishCommand()) return true} else if (char === ' ' || char === '\t' || char === '\r' || char === '\n' ||- ';|&()<>\x60'.includes(char)) {+ ';|&()<>'.includes(char)) {if (finishWord()) return true// Redirections separate words, but later operands still belong to rm.redirect = char === '<' || char === '>'- if (!redirectionAmpersand && (char === '\n' || ';|&()\x60'.includes(char)) && finishCommand()) return true+ if (!redirectionAmpersand && (char === '\n' || ';|&()'.includes(char)) && finishCommand()) return true} else {word += char; started = true}diff --git a/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts b/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.tsindex 8677c22b95..e434035288 100644--- a/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts+++ b/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts@@ -308,6 +308,13 @@ describe('#3698 root deletion guard parity', () => {['rm --r --f /', true],['rm --recur --forc /*', true],['rm --rec -f /', true],+ // An empty substitution among rm's operands is dropped by the shell: rm keeps its state.+ ['rm -rf `true` /', true],+ ['rm `` -rf /', true],+ ['rm -rf /tmp/x `:` /', true],+ ['rm -r `:` -f /', true],+ ['git commit -m "fix `rm` docs"', false],+ ['echo `ls` /tmp', false],['format c: /q /y', true],['del /s /q c:\\', true],[':(){:|:&};:', true],diff --git a/v3/@claude-flow/cli/src/init/helpers-generator.ts b/v3/@claude-flow/cli/src/init/helpers-generator.tsindex c92d7cab50..058c69e366 100644--- a/v3/@claude-flow/cli/src/init/helpers-generator.ts+++ b/v3/@claude-flow/cli/src/init/helpers-generator.ts@@ -494,6 +494,15 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw`function hasRootDelete(command, deptif (char === '\\' && i + 1 < command.length) {const next = command[++i]if (next !== '\n') { word += next; started = true }+ } else if (char === '\x60') {+ // Command substitution: scan the body as its own command; the substitution+ // stays inside the enclosing word, so the rm being parsed keeps its state.+ let body = ''+ for (i++; i < command.length && command[i] !== '\x60'; i++) {+ if (command[i] === '\\' && i + 1 < command.length) i+++ body += command[i]+ }+ if (depth < 4 ? hasRootDelete(body, depth + 1) : body.includes('rm -rf /')) return true} else if (char === '$' && (command[i + 1] === "'" || command[i + 1] === '"')) {// ANSI-C ($'...') and locale ($"...") quoting: the $ is not part of the word.} else if (char === '"' || char === "'") {@@ -502,11 +511,11 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw`function hasRootDelete(command, deptwhile (i < command.length && command[i] !== '\n') i++if (finishCommand()) return true} else if (char === ' ' || char === '\t' || char === '\r' || char === '\n' ||- ';|&()<>\x60'.includes(char)) {+ ';|&()<>'.includes(char)) {if (finishWord()) return true// Redirections separate words, but later operands still belong to rm.redirect = char === '<' || char === '>'- if (!redirectionAmpersand && (char === '\n' || ';|&()\x60'.includes(char)) && finishCommand()) return true+ if (!redirectionAmpersand && (char === '\n' || ';|&()'.includes(char)) && finishCommand()) return true} else {word += char; started = true}