🌊 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): root-delete scanner catches backticks, $'…' quoting and abbreviated long options (#3791)
Dragan Spiridonov574e5dd6daf1
diff --git a/.claude/helpers/hook-handler.cjs b/.claude/helpers/hook-handler.cjsindex 5677eab738..9d598dcc44 100755--- a/.claude/helpers/hook-handler.cjs+++ b/.claude/helpers/hook-handler.cjs@@ -501,14 +501,15 @@ 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;&|()]/.test(word)) {+ if (word.includes('rm') && /[\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')else if (!optionsEnded && word === '--') optionsEnded = trueelse if (!optionsEnded && word.startsWith('-')) {- recursive = recursive || word === '--recursive' || /^-[a-z]*r[a-z]*$/.test(word)- force = force || word === '--force' || /^-[a-z]*f[a-z]*$/.test(word)+ // GNU getopt accepts any unambiguous long-option prefix: --r, --recur, --forc.+ recursive = recursive || (word.length > 2 && '--recursive'.startsWith(word)) || /^-[a-z]*r[a-z]*$/.test(word)+ force = force || (word.length > 2 && '--force'.startsWith(word)) || /^-[a-z]*f[a-z]*$/.test(word)} else root = root || isRoot(word)word = ''; started = falsereturn inRm && recursive && force && root@@ -535,17 +536,19 @@ const handlers = {if (char === '\\' && i + 1 < command.length) {const next = command[++i]if (next !== '\n') { word += next; started = 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 === "'") {quote = char; started = true} else if (char === '#' && !started) {while (i < command.length && command[i] !== '\n') i++if (finishCommand()) return true} else if (char === ' ' || char === '\t' || char === '\r' || char === '\n' ||- ';|&()<>'.includes(char)) {+ ';|&()<>\x60'.includes(char)) {if (finishWord()) return true// Redirections separate words, but later operands still belong to rm.redirect = char === '<' || char === '>'- if (!redirectionAmpersand && (char === '\n' || ';|&()'.includes(char)) && finishCommand()) return true+ if (!redirectionAmpersand && (char === '\n' || ';|&()\x60'.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 3d8a762f07..9b6a1b843a 100644--- a/plugins/ruflo-mods/hooks/guard/dangerous-command.ts+++ b/plugins/ruflo-mods/hooks/guard/dangerous-command.ts@@ -26,14 +26,15 @@ 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;&|()]/.test(word)) {+ if (word.includes('rm') && /[\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')else if (!optionsEnded && word === '--') optionsEnded = trueelse if (!optionsEnded && word.startsWith('-')) {- recursive = recursive || word === '--recursive' || /^-[a-z]*r[a-z]*$/.test(word)- force = force || word === '--force' || /^-[a-z]*f[a-z]*$/.test(word)+ // GNU getopt accepts any unambiguous long-option prefix: --r, --recur, --forc.+ recursive = recursive || (word.length > 2 && '--recursive'.startsWith(word)) || /^-[a-z]*r[a-z]*$/.test(word)+ force = force || (word.length > 2 && '--force'.startsWith(word)) || /^-[a-z]*f[a-z]*$/.test(word)} else root = root || isRoot(word)word = ''; started = falsereturn inRm && recursive && force && root@@ -60,17 +61,19 @@ 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 === '$' && (command[i + 1] === "'" || command[i + 1] === '"')) {+ // ANSI-C ($'...') and locale ($"...") quoting: the $ is not part of the word.} else if (char === '"' || char === "'") {quote = char; started = true} else if (char === '#' && !started) {while (i < command.length && command[i] !== '\n') i++if (finishCommand()) return true} else if (char === ' ' || char === '\t' || char === '\r' || char === '\n' ||- ';|&()<>'.includes(char)) {+ ';|&()<>\x60'.includes(char)) {if (finishWord()) return true// Redirections separate words, but later operands still belong to rm.redirect = char === '<' || char === '>'- if (!redirectionAmpersand && (char === '\n' || ';|&()'.includes(char)) && finishCommand()) return true+ if (!redirectionAmpersand && (char === '\n' || ';|&()\x60'.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 5677eab738..9d598dcc44 100755--- a/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs+++ b/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs@@ -501,14 +501,15 @@ 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;&|()]/.test(word)) {+ if (word.includes('rm') && /[\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')else if (!optionsEnded && word === '--') optionsEnded = trueelse if (!optionsEnded && word.startsWith('-')) {- recursive = recursive || word === '--recursive' || /^-[a-z]*r[a-z]*$/.test(word)- force = force || word === '--force' || /^-[a-z]*f[a-z]*$/.test(word)+ // GNU getopt accepts any unambiguous long-option prefix: --r, --recur, --forc.+ recursive = recursive || (word.length > 2 && '--recursive'.startsWith(word)) || /^-[a-z]*r[a-z]*$/.test(word)+ force = force || (word.length > 2 && '--force'.startsWith(word)) || /^-[a-z]*f[a-z]*$/.test(word)} else root = root || isRoot(word)word = ''; started = falsereturn inRm && recursive && force && root@@ -535,17 +536,19 @@ const handlers = {if (char === '\\' && i + 1 < command.length) {const next = command[++i]if (next !== '\n') { word += next; started = 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 === "'") {quote = char; started = true} else if (char === '#' && !started) {while (i < command.length && command[i] !== '\n') i++if (finishCommand()) return true} else if (char === ' ' || char === '\t' || char === '\r' || char === '\n' ||- ';|&()<>'.includes(char)) {+ ';|&()<>\x60'.includes(char)) {if (finishWord()) return true// Redirections separate words, but later operands still belong to rm.redirect = char === '<' || char === '>'- if (!redirectionAmpersand && (char === '\n' || ';|&()'.includes(char)) && finishCommand()) return true+ if (!redirectionAmpersand && (char === '\n' || ';|&()\x60'.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 fe81a58af8..8677c22b95 100644--- a/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts+++ b/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts@@ -292,6 +292,22 @@ describe('#3698 root deletion guard parity', () => {['rm -rf /|cat', true],['(rm -rf /)', true],['rm -rf /\nprintf ok', true],+ // Command substitution, ANSI-C/locale quoting and GNU long-option prefixes.+ ['echo `date` /', false],+ ['rm --r /tmp/ruflo-test /', false],+ ['rm --forc /tmp/ruflo-test /', false],+ ["rm --rec --forc '/tmp/ruflo test'", false],+ ["printf $'rm -rf /tmp\\n'", false],+ ['echo `rm -rf /`', true],+ ['echo "`rm -rf /`"', true],+ ['bash -c "echo `rm -rf /`"', true],+ ['`rm -rf /`', true],+ ["$'rm' -rf /", true],+ ['$"rm" -rf /', true],+ ["bash -c $'rm -rf /'", true],+ ['rm --r --f /', true],+ ['rm --recur --forc /*', true],+ ['rm --rec -f /', true],['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 3a95ef6075..c92d7cab50 100644--- a/v3/@claude-flow/cli/src/init/helpers-generator.ts+++ b/v3/@claude-flow/cli/src/init/helpers-generator.ts@@ -459,14 +459,15 @@ 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;&|()]/.test(word)) {+ if (word.includes('rm') && /[\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')else if (!optionsEnded && word === '--') optionsEnded = trueelse if (!optionsEnded && word.startsWith('-')) {- recursive = recursive || word === '--recursive' || /^-[a-z]*r[a-z]*$/.test(word)- force = force || word === '--force' || /^-[a-z]*f[a-z]*$/.test(word)+ // GNU getopt accepts any unambiguous long-option prefix: --r, --recur, --forc.+ recursive = recursive || (word.length > 2 && '--recursive'.startsWith(word)) || /^-[a-z]*r[a-z]*$/.test(word)+ force = force || (word.length > 2 && '--force'.startsWith(word)) || /^-[a-z]*f[a-z]*$/.test(word)} else root = root || isRoot(word)word = ''; started = falsereturn inRm && recursive && force && root@@ -493,17 +494,19 @@ 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 === '$' && (command[i + 1] === "'" || command[i + 1] === '"')) {+ // ANSI-C ($'...') and locale ($"...") quoting: the $ is not part of the word.} else if (char === '"' || char === "'") {quote = char; started = true} else if (char === '#' && !started) {while (i < command.length && command[i] !== '\n') i++if (finishCommand()) return true} else if (char === ' ' || char === '\t' || char === '\r' || char === '\n' ||- ';|&()<>'.includes(char)) {+ ';|&()<>\x60'.includes(char)) {if (finishWord()) return true// Redirections separate words, but later operands still belong to rm.redirect = char === '<' || char === '>'- if (!redirectionAmpersand && (char === '\n' || ';|&()'.includes(char)) && finishCommand()) return true+ if (!redirectionAmpersand && (char === '\n' || ';|&()\x60'.includes(char)) && finishCommand()) return true} else {word += char; started = true}