🌊 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): unescape a substitution body as bash does, scan backticks inside double quotes, rescan any word with a separator (#3791)
Dragan Spiridonovb880b825ff1f
diff --git a/.claude/helpers/hook-handler.cjs b/.claude/helpers/hook-handler.cjsindex 953071aaca..4a9b8adbd3 100755--- a/.claude/helpers/hook-handler.cjs+++ b/.claude/helpers/hook-handler.cjs@@ -501,7 +501,7 @@ const handlers = {if (!started) return false// Literal shell strings (e.g. sh -c 'rm -rf /') also carried the old guard.// Bound rescanning to four levels; beyond that retain its conservative check.- if (word.includes('rm') && /[\s;&|()\x60]/.test(word)) {+ if (/[\s;&|()\x60]/.test(word)) {if (depth < 4 ? hasRootDelete(word, depth + 1) : word.includes('rm -rf /')) return true}if (!inRm) inRm = word === 'rm' || word.endsWith('/rm')@@ -514,6 +514,21 @@ const handlers = {word = ''; started = falsereturn inRm && recursive && force && root}+ // A command substitution's body, from just after its opening backtick. Bash removes a+ // backslash only before $, a backtick or a backslash (and " inside double quotes) and+ // drops backslash-newline; any other backslash stays for the nested scan.+ const substitution = (from, inDouble) => {+ let body = '', j = from+ for (; j < command.length && command[j] !== '\x60'; j++) {+ const next = command[j + 1]+ if (command[j] === '\\' && j + 1 < command.length) {+ if (next === '\n') { j++; continue }+ if (next === '$' || next === '\x60' || next === '\\' || (inDouble && next === '"')) { body += next; j++; continue }+ }+ body += command[j]+ }+ return [j, depth < 4 ? hasRootDelete(body, depth + 1) : body.includes('rm -rf /')]+ }const finishCommand = () => {const denied = inRm && recursive && force && rootinRm = optionsEnded = recursive = force = root = false@@ -525,6 +540,11 @@ const handlers = {redirect = falseif (quote) {if (char === quote) quote = ''+ else if (quote === '"' && char === '\x60') {+ const [end, denied] = substitution(i + 1, true)+ if (denied) return true+ i = end+ }else if (quote === '"' && char === '\\' && i + 1 < command.length &&(command[i + 1] === '"' || command[i + 1] === '\\' || command[i + 1] === '$' ||command.charCodeAt(i + 1) === 96 || command[i + 1] === '\n')) {@@ -539,12 +559,9 @@ const handlers = {} 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+ const [end, denied] = substitution(i + 1, false)+ if (denied) return true+ i = end} 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 === "'") {diff --git a/plugins/ruflo-mods/hooks/guard/dangerous-command.ts b/plugins/ruflo-mods/hooks/guard/dangerous-command.tsindex 0acb7cd90c..5068615522 100644--- a/plugins/ruflo-mods/hooks/guard/dangerous-command.ts+++ b/plugins/ruflo-mods/hooks/guard/dangerous-command.ts@@ -26,7 +26,7 @@ function hasRootDelete(command: string, depth = 0): boolean {if (!started) return false// Literal shell strings (e.g. sh -c 'rm -rf /') also carried the old guard.// Bound rescanning to four levels; beyond that retain its conservative check.- if (word.includes('rm') && /[\s;&|()\x60]/.test(word)) {+ if (/[\s;&|()\x60]/.test(word)) {if (depth < 4 ? hasRootDelete(word, depth + 1) : word.includes('rm -rf /')) return true}if (!inRm) inRm = word === 'rm' || word.endsWith('/rm')@@ -39,6 +39,21 @@ function hasRootDelete(command: string, depth = 0): boolean {word = ''; started = falsereturn inRm && recursive && force && root}+ // A command substitution's body, from just after its opening backtick. Bash removes a+ // backslash only before $, a backtick or a backslash (and " inside double quotes) and+ // drops backslash-newline; any other backslash stays for the nested scan.+ const substitution = (from: number, inDouble: boolean): [number, boolean] => {+ let body = '', j = from+ for (; j < command.length && command[j] !== '\x60'; j++) {+ const next = command[j + 1]+ if (command[j] === '\\' && j + 1 < command.length) {+ if (next === '\n') { j++; continue }+ if (next === '$' || next === '\x60' || next === '\\' || (inDouble && next === '"')) { body += next; j++; continue }+ }+ body += command[j]+ }+ return [j, depth < 4 ? hasRootDelete(body, depth + 1) : body.includes('rm -rf /')]+ }const finishCommand = () => {const denied = inRm && recursive && force && rootinRm = optionsEnded = recursive = force = root = false@@ -50,6 +65,11 @@ function hasRootDelete(command: string, depth = 0): boolean {redirect = falseif (quote) {if (char === quote) quote = ''+ else if (quote === '"' && char === '\x60') {+ const [end, denied] = substitution(i + 1, true)+ if (denied) return true+ i = end+ }else if (quote === '"' && char === '\\' && i + 1 < command.length &&(command[i + 1] === '"' || command[i + 1] === '\\' || command[i + 1] === '$' ||command.charCodeAt(i + 1) === 96 || command[i + 1] === '\n')) {@@ -64,12 +84,9 @@ function hasRootDelete(command: string, depth = 0): boolean {} 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+ const [end, denied] = substitution(i + 1, false)+ if (denied) return true+ i = end} 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 === "'") {diff --git a/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs b/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjsindex 953071aaca..4a9b8adbd3 100755--- a/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs+++ b/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs@@ -501,7 +501,7 @@ const handlers = {if (!started) return false// Literal shell strings (e.g. sh -c 'rm -rf /') also carried the old guard.// Bound rescanning to four levels; beyond that retain its conservative check.- if (word.includes('rm') && /[\s;&|()\x60]/.test(word)) {+ if (/[\s;&|()\x60]/.test(word)) {if (depth < 4 ? hasRootDelete(word, depth + 1) : word.includes('rm -rf /')) return true}if (!inRm) inRm = word === 'rm' || word.endsWith('/rm')@@ -514,6 +514,21 @@ const handlers = {word = ''; started = falsereturn inRm && recursive && force && root}+ // A command substitution's body, from just after its opening backtick. Bash removes a+ // backslash only before $, a backtick or a backslash (and " inside double quotes) and+ // drops backslash-newline; any other backslash stays for the nested scan.+ const substitution = (from, inDouble) => {+ let body = '', j = from+ for (; j < command.length && command[j] !== '\x60'; j++) {+ const next = command[j + 1]+ if (command[j] === '\\' && j + 1 < command.length) {+ if (next === '\n') { j++; continue }+ if (next === '$' || next === '\x60' || next === '\\' || (inDouble && next === '"')) { body += next; j++; continue }+ }+ body += command[j]+ }+ return [j, depth < 4 ? hasRootDelete(body, depth + 1) : body.includes('rm -rf /')]+ }const finishCommand = () => {const denied = inRm && recursive && force && rootinRm = optionsEnded = recursive = force = root = false@@ -525,6 +540,11 @@ const handlers = {redirect = falseif (quote) {if (char === quote) quote = ''+ else if (quote === '"' && char === '\x60') {+ const [end, denied] = substitution(i + 1, true)+ if (denied) return true+ i = end+ }else if (quote === '"' && char === '\\' && i + 1 < command.length &&(command[i + 1] === '"' || command[i + 1] === '\\' || command[i + 1] === '$' ||command.charCodeAt(i + 1) === 96 || command[i + 1] === '\n')) {@@ -539,12 +559,9 @@ const handlers = {} 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+ const [end, denied] = substitution(i + 1, false)+ if (denied) return true+ i = end} 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 === "'") {diff --git a/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts b/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.tsindex e434035288..576d0154b4 100644--- a/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts+++ b/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts@@ -314,6 +314,13 @@ describe('#3698 root deletion guard parity', () => {['rm -rf /tmp/x `:` /', true],['rm -r `:` -f /', true],['git commit -m "fix `rm` docs"', false],+ // A substitution body is unescaped as bash does it, and one inside double quotes is a substitution too.+ ['echo `rm -rf \\( /`', true],+ ['echo `rm -rf \\\n/`', true],+ ['rm -rf "/`true`"', true],+ ['echo "`r\\`\\`m -rf /`"', true],+ ["sh -c 'r``m -rf /'", true],+ ['echo "`date`" /tmp', false],['echo `ls` /tmp', false],['format c: /q /y', true],['del /s /q c:\\', true],diff --git a/v3/@claude-flow/cli/src/init/helpers-generator.ts b/v3/@claude-flow/cli/src/init/helpers-generator.tsindex 058c69e366..a55fc7271f 100644--- a/v3/@claude-flow/cli/src/init/helpers-generator.ts+++ b/v3/@claude-flow/cli/src/init/helpers-generator.ts@@ -459,7 +459,7 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw`function hasRootDelete(command, deptif (!started) return false// Literal shell strings (e.g. sh -c 'rm -rf /') also carried the old guard.// Bound rescanning to four levels; beyond that retain its conservative check.- if (word.includes('rm') && /[\s;&|()\x60]/.test(word)) {+ if (/[\s;&|()\x60]/.test(word)) {if (depth < 4 ? hasRootDelete(word, depth + 1) : word.includes('rm -rf /')) return true}if (!inRm) inRm = word === 'rm' || word.endsWith('/rm')@@ -472,6 +472,21 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw`function hasRootDelete(command, deptword = ''; started = falsereturn inRm && recursive && force && root}+ // A command substitution's body, from just after its opening backtick. Bash removes a+ // backslash only before $, a backtick or a backslash (and " inside double quotes) and+ // drops backslash-newline; any other backslash stays for the nested scan.+ const substitution = (from, inDouble) => {+ let body = '', j = from+ for (; j < command.length && command[j] !== '\x60'; j++) {+ const next = command[j + 1]+ if (command[j] === '\\' && j + 1 < command.length) {+ if (next === '\n') { j++; continue }+ if (next === '$' || next === '\x60' || next === '\\' || (inDouble && next === '"')) { body += next; j++; continue }+ }+ body += command[j]+ }+ return [j, depth < 4 ? hasRootDelete(body, depth + 1) : body.includes('rm -rf /')]+ }const finishCommand = () => {const denied = inRm && recursive && force && rootinRm = optionsEnded = recursive = force = root = false@@ -483,6 +498,11 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw`function hasRootDelete(command, deptredirect = falseif (quote) {if (char === quote) quote = ''+ else if (quote === '"' && char === '\x60') {+ const [end, denied] = substitution(i + 1, true)+ if (denied) return true+ i = end+ }else if (quote === '"' && char === '\\' && i + 1 < command.length &&(command[i + 1] === '"' || command[i + 1] === '\\' || command[i + 1] === '$' ||command.charCodeAt(i + 1) === 96 || command[i + 1] === '\n')) {@@ -497,12 +517,9 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw`function hasRootDelete(command, dept} 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+ const [end, denied] = substitution(i + 1, false)+ if (denied) return true+ i = end} 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 === "'") {