Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

fix(guard): a substitution starts its word, and an unterminated backtick is text (#3791)

Dragan Spiridonov94238f06ef6c
diff --git a/.claude/helpers/hook-handler.cjs b/.claude/helpers/hook-handler.cjs
index 4a9b8adbd3..88dc1f1d7b 100755
--- a/.claude/helpers/hook-handler.cjs
+++ b/.claude/helpers/hook-handler.cjs
@@ -540,7 +540,7 @@ const handlers = {
redirect = false
if (quote) {
if (char === quote) quote = ''
- else if (quote === '"' && char === '\x60') {
+ else if (quote === '"' && char === '\x60' && command.indexOf('\x60', i + 1) > i) {
const [end, denied] = substitution(i + 1, true)
if (denied) return true
i = end
@@ -556,12 +556,13 @@ const handlers = {
if (char === '\\' && i + 1 < command.length) {
const next = command[++i]
if (next !== '\n') { word += next; started = true }
- } else if (char === '\x60') {
+ } else if (char === '\x60' && command.indexOf('\x60', i + 1) > i) {
// Command substitution: scan the body as its own command; the substitution
- // stays inside the enclosing word, so the rm being parsed keeps its state.
+ // stays inside the enclosing word, so the rm being parsed keeps its state,
+ // and the word has started (a # right after it is not a comment).
const [end, denied] = substitution(i + 1, false)
if (denied) return true
- i = end
+ i = end; 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 === "'") {
diff --git a/plugins/ruflo-mods/hooks/guard/dangerous-command.ts b/plugins/ruflo-mods/hooks/guard/dangerous-command.ts
index 5068615522..98976f8284 100644
--- a/plugins/ruflo-mods/hooks/guard/dangerous-command.ts
+++ b/plugins/ruflo-mods/hooks/guard/dangerous-command.ts
@@ -65,7 +65,7 @@ function hasRootDelete(command: string, depth = 0): boolean {
redirect = false
if (quote) {
if (char === quote) quote = ''
- else if (quote === '"' && char === '\x60') {
+ else if (quote === '"' && char === '\x60' && command.indexOf('\x60', i + 1) > i) {
const [end, denied] = substitution(i + 1, true)
if (denied) return true
i = end
@@ -81,12 +81,13 @@ 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') {
+ } else if (char === '\x60' && command.indexOf('\x60', i + 1) > i) {
// Command substitution: scan the body as its own command; the substitution
- // stays inside the enclosing word, so the rm being parsed keeps its state.
+ // stays inside the enclosing word, so the rm being parsed keeps its state,
+ // and the word has started (a # right after it is not a comment).
const [end, denied] = substitution(i + 1, false)
if (denied) return true
- i = end
+ i = end; 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 === "'") {
diff --git a/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs b/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs
index 4a9b8adbd3..88dc1f1d7b 100755
--- a/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs
+++ b/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs
@@ -540,7 +540,7 @@ const handlers = {
redirect = false
if (quote) {
if (char === quote) quote = ''
- else if (quote === '"' && char === '\x60') {
+ else if (quote === '"' && char === '\x60' && command.indexOf('\x60', i + 1) > i) {
const [end, denied] = substitution(i + 1, true)
if (denied) return true
i = end
@@ -556,12 +556,13 @@ const handlers = {
if (char === '\\' && i + 1 < command.length) {
const next = command[++i]
if (next !== '\n') { word += next; started = true }
- } else if (char === '\x60') {
+ } else if (char === '\x60' && command.indexOf('\x60', i + 1) > i) {
// Command substitution: scan the body as its own command; the substitution
- // stays inside the enclosing word, so the rm being parsed keeps its state.
+ // stays inside the enclosing word, so the rm being parsed keeps its state,
+ // and the word has started (a # right after it is not a comment).
const [end, denied] = substitution(i + 1, false)
if (denied) return true
- i = end
+ i = end; 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 === "'") {
diff --git a/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts b/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts
index 576d0154b4..631d341d1f 100644
--- a/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts
+++ b/v3/@claude-flow/cli/__tests__/mods/mods-guard.test.ts
@@ -321,6 +321,12 @@ describe('#3698 root deletion guard parity', () => {
['echo "`r\\`\\`m -rf /`"', true],
["sh -c 'r``m -rf /'", true],
['echo "`date`" /tmp', false],
+ // A # right after a substitution is part of the word, not a comment; an unterminated backtick is text.
+ ['`true`#x; rm -rf /', true],
+ ['echo a`true`#b; rm -rf /', true],
+ ['echo it` costs; rm -rf /', true],
+ ['echo "a ` b"; rm -rf /', true],
+ ['echo "a ` b"; ls /', 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.ts
index a55fc7271f..912ed43b8b 100644
--- a/v3/@claude-flow/cli/src/init/helpers-generator.ts
+++ b/v3/@claude-flow/cli/src/init/helpers-generator.ts
@@ -498,7 +498,7 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw`function hasRootDelete(command, dept
redirect = false
if (quote) {
if (char === quote) quote = ''
- else if (quote === '"' && char === '\x60') {
+ else if (quote === '"' && char === '\x60' && command.indexOf('\x60', i + 1) > i) {
const [end, denied] = substitution(i + 1, true)
if (denied) return true
i = end
@@ -514,12 +514,13 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw`function hasRootDelete(command, dept
if (char === '\\' && i + 1 < command.length) {
const next = command[++i]
if (next !== '\n') { word += next; started = true }
- } else if (char === '\x60') {
+ } else if (char === '\x60' && command.indexOf('\x60', i + 1) > i) {
// Command substitution: scan the body as its own command; the substitution
- // stays inside the enclosing word, so the rm being parsed keeps its state.
+ // stays inside the enclosing word, so the rm being parsed keeps its state,
+ // and the word has started (a # right after it is not a comment).
const [end, denied] = substitution(i + 1, false)
if (denied) return true
- i = end
+ i = end; 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 === "'") {