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(hooks): #2017 β€” defensive pre-bash + new CI gate against silent-swallow shape

Reuvend5dbfa4b9296
diff --git a/.claude/helpers/hook-handler.cjs b/.claude/helpers/hook-handler.cjs
index f7907e3573..93a3e6312b 100644
--- a/.claude/helpers/hook-handler.cjs
+++ b/.claude/helpers/hook-handler.cjs
@@ -131,7 +131,10 @@ const handlers = {
},
'pre-bash': () => {
- var cmd = (hookInput.command || prompt).toLowerCase();
+ // String() wrap is belt-and-suspenders for #2017: even if a future regression
+ // re-binds `prompt` or `hookInput.command` to a non-string, `.toLowerCase()`
+ // can no longer throw a TypeError that the global try/catch would swallow.
+ var cmd = String(hookInput.command || toolInput.command || prompt || '').toLowerCase();
var dangerous = ['rm -rf /', 'format c:', 'del /s /q c:\\', ':(){:|:&};:'];
for (var i = 0; i < dangerous.length; i++) {
if (cmd.includes(dangerous[i])) {
diff --git a/.github/workflows/v3-ci.yml b/.github/workflows/v3-ci.yml
index 8f418c6717..9682398313 100644
--- a/.github/workflows/v3-ci.yml
+++ b/.github/workflows/v3-ci.yml
@@ -16,6 +16,8 @@ on:
# hook-command audit (#1921) β€” every plugin hooks.json + the ruflo-hook shims
- '**/hooks/hooks.json'
- '**/scripts/ruflo-hook.sh'
+ # pre-bash hook safety (#2017) β€” both handler copies trigger the smoke
+ - '**/.claude/helpers/hook-handler.cjs'
pull_request:
branches: [main]
paths:
@@ -25,6 +27,7 @@ on:
- 'scripts/**'
- '**/hooks/hooks.json'
- '**/scripts/ruflo-hook.sh'
+ - '**/.claude/helpers/hook-handler.cjs'
# witness manifests / fix list β€” so witness-verify runs on PRs that
# touch them (otherwise a stale per-OS manifest only fails post-merge).
- 'verification/**'
@@ -302,6 +305,41 @@ jobs:
node plugins/ruflo-core/scripts/test-hooks.mjs \
"node $GITHUB_WORKSPACE/v3/@claude-flow/cli/bin/cli.js"
+ pre-bash-hook-smoke:
+ # Regression guard for ruvnet/ruflo#2017 β€” the `pre-bash` PreToolUse hook
+ # in `.claude/helpers/hook-handler.cjs` is a security gate that refuses to
+ # run dangerous commands (`rm -rf /`, fork bombs, etc.). In 3.6.30 it
+ # silently exited 0 on every dangerous payload because the handler read
+ # the wrong stdin field (`toolInput` object instead of
+ # `toolInput.command` string), `.toLowerCase()` threw TypeError, and the
+ # global safety-timer try/catch swallowed it β€” printing a misleading
+ # "[OK] Command validated" while letting the dangerous command through.
+ #
+ # This smoke drives real Claude-Code-shaped PreToolUse JSON into BOTH
+ # the published template (v3/@claude-flow/cli/.claude/helpers/) and the
+ # repo's dogfood copy (.claude/helpers/), and fails on any of:
+ # - dangerous command + exit 0 (the security bypass)
+ # - "[OK] Command validated" on a dangerous input (the misleading log)
+ # - "[WARN] Hook X encountered an error" anywhere (silent-swallow shape)
+ #
+ # Independent job (not nested in plugin-hooks-smoke) so the gate is
+ # individually visible and the CI summary names the failure clearly.
+ name: pre-bash hook safety smoke (#2017)
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Setup Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: '22'
+
+ - name: Drive Claude-Code-shaped PreToolUse JSON through both handler copies
+ shell: bash
+ run: node scripts/smoke-pre-bash-hook.mjs
+
mcp-protocol-smoke:
# Regression guard for ruvnet/ruflo#1874 β€” boots the HTTP MCP server,
# sends a real `initialize` request, and validates the response wire
@@ -673,7 +711,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
- needs: [smoke-install-no-bsqlite, plugin-hooks-smoke, mcp-protocol-smoke, memory-import-smoke, tool-descriptions-audit, mcp-roundtrip-smoke, plugin-package-audit, cli-npx-install-smoke, hook-command-audit, vector-dim-audit]
+ needs: [smoke-install-no-bsqlite, plugin-hooks-smoke, pre-bash-hook-smoke, mcp-protocol-smoke, memory-import-smoke, tool-descriptions-audit, mcp-roundtrip-smoke, plugin-package-audit, cli-npx-install-smoke, hook-command-audit, vector-dim-audit]
steps:
- name: Checkout code
diff --git a/package.json b/package.json
index 800ded8d2a..096f6defe9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "claude-flow",
- "version": "3.7.0-alpha.39",
+ "version": "3.7.0-alpha.40",
"description": "Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
"main": "dist/index.js",
"type": "module",
diff --git a/ruflo/package.json b/ruflo/package.json
index 121168d59e..8003a309b9 100644
--- a/ruflo/package.json
+++ b/ruflo/package.json
@@ -1,6 +1,6 @@
{
"name": "ruflo",
- "version": "3.7.0-alpha.39",
+ "version": "3.7.0-alpha.40",
"description": "Ruflo - Enterprise AI agent orchestration platform. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
"main": "bin/ruflo.js",
"type": "module",
diff --git a/scripts/smoke-pre-bash-hook.mjs b/scripts/smoke-pre-bash-hook.mjs
new file mode 100644
index 0000000000..f61cc88ccf
--- /dev/null
+++ b/scripts/smoke-pre-bash-hook.mjs
@@ -0,0 +1,150 @@
+#!/usr/bin/env node
+/**
+ * Regression guard for ruvnet/ruflo#2017.
+ *
+ * The `pre-bash` PreToolUse hook in `.claude/helpers/hook-handler.cjs` reads
+ * the command Claude Code is about to execute and refuses to run dangerous
+ * ones (`rm -rf /`, `format c:`, etc.). In 3.6.30 the handler read the wrong
+ * field β€” `toolInput` (the object) instead of `toolInput.command` (the
+ * string) β€” so `.toLowerCase()` threw TypeError on every Bash call, was
+ * swallowed by the global safety timer, and the handler exited 0 with a
+ * misleading `[OK] Command validated`. Dangerous commands sailed through.
+ *
+ * This script pipes real-shaped Claude Code PreToolUse JSON into the
+ * locally-built handler and asserts:
+ *
+ * - dangerous command β†’ exit 1 + `[BLOCKED] Dangerous command detected:`
+ * - innocuous command β†’ exit 0 + `[OK] Command validated`
+ * - empty payload β†’ exit 0 (no crash, no false positive)
+ * - non-string command field β†’ exit 0 (defensive String() wrap holds)
+ *
+ * Runs against BOTH copies of the handler in the repo:
+ * 1. v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs (the published template)
+ * 2. .claude/helpers/hook-handler.cjs (the dogfood copy)
+ *
+ * Failure of either fails the build.
+ */
+
+import { spawnSync } from 'node:child_process';
+import { existsSync } from 'node:fs';
+import { join } from 'node:path';
+
+const REPO_ROOT = process.cwd();
+const HANDLERS = [
+ join(REPO_ROOT, 'v3', '@claude-flow', 'cli', '.claude', 'helpers', 'hook-handler.cjs'),
+ join(REPO_ROOT, '.claude', 'helpers', 'hook-handler.cjs'),
+];
+
+const cases = [
+ {
+ name: 'dangerous rm -rf / β†’ BLOCKED',
+ input: { tool_name: 'Bash', tool_input: { command: 'rm -rf / --no-preserve-root' } },
+ expectExit: 1,
+ expectStderrIncludes: '[BLOCKED]',
+ },
+ {
+ name: 'innocuous ls -la β†’ OK',
+ input: { tool_name: 'Bash', tool_input: { command: 'ls -la' } },
+ expectExit: 0,
+ expectStdoutIncludes: '[OK] Command validated',
+ },
+ {
+ name: 'empty payload β†’ no crash, no false block',
+ input: {},
+ expectExit: 0,
+ },
+ {
+ // Defensive String() wrap: even if a future regression binds command to
+ // null / undefined / an object, the handler must not throw and silently
+ // exit 0 from the global safety catch.
+ name: 'null command field β†’ no crash',
+ input: { tool_name: 'Bash', tool_input: { command: null } },
+ expectExit: 0,
+ },
+ {
+ // The exact #2017 shape: the handler reads `toolInput` (object) instead
+ // of `toolInput.command` (string), so `.toLowerCase()` throws TypeError,
+ // global try/catch swallows, exits 0. This case asserts the regression
+ // CAN'T return: a dangerous command sent in real Claude Code's snake_case
+ // shape must still BLOCK. If a future refactor binds command to a
+ // non-string and the safety check no-ops, this case fails loudly.
+ name: '#2017 shape: snake_case tool_input.command dangerous β†’ BLOCKED',
+ input: { tool_name: 'Bash', tool_input: { command: 'rm -rf / --no-preserve-root' } },
+ expectExit: 1,
+ expectStderrIncludes: '[BLOCKED]',
+ },
+ {
+ name: 'fork-bomb signature β†’ BLOCKED',
+ input: { tool_name: 'Bash', tool_input: { command: ':(){:|:&};:' } },
+ expectExit: 1,
+ expectStderrIncludes: '[BLOCKED]',
+ },
+ {
+ name: 'format c: β†’ BLOCKED',
+ input: { tool_name: 'Bash', tool_input: { command: 'format c: /q /y' } },
+ expectExit: 1,
+ expectStderrIncludes: '[BLOCKED]',
+ },
+];
+
+function runOne(handlerPath, c) {
+ const payload = JSON.stringify(c.input);
+ const r = spawnSync('node', [handlerPath, 'pre-bash'], {
+ input: payload,
+ encoding: 'utf-8',
+ timeout: 10_000,
+ });
+ const out = r.stdout || '';
+ const err = r.stderr || '';
+ const fails = [];
+ if (r.status !== c.expectExit) {
+ fails.push(`exit ${r.status} (expected ${c.expectExit})`);
+ }
+ if (c.expectStdoutIncludes && !out.includes(c.expectStdoutIncludes)) {
+ fails.push(`stdout missing "${c.expectStdoutIncludes}"`);
+ }
+ if (c.expectStderrIncludes && !err.includes(c.expectStderrIncludes)) {
+ fails.push(`stderr missing "${c.expectStderrIncludes}"`);
+ }
+ // Catch the #2017 silent-swallow shape: a [WARN] from the global try/catch
+ // PLUS a 0 exit code means a real handler error was hidden. ANY case
+ // (dangerous OR innocuous) where we see [WARN] ... encountered an error
+ // is a real bug β€” the safety gate is no longer running its check.
+ if (/\[WARN\] Hook .* encountered an error/.test(err)) {
+ fails.push(`handler error swallowed by global catch (regression of #2017): ${err.trim().split('\n')[0]}`);
+ }
+ // Also catch the "[OK] Command validated" + dangerous input + exit 0 shape
+ // directly β€” the form the published 3.6.30 actually printed before the
+ // global-catch warning was added.
+ if (c.expectExit === 1 && /\[OK\] Command validated/.test(out) && r.status === 0) {
+ fails.push('dangerous command produced [OK] + exit 0 (regression of #2017)');
+ }
+ return { fails, out, err, status: r.status };
+}
+
+let failed = 0;
+for (const handlerPath of HANDLERS) {
+ if (!existsSync(handlerPath)) {
+ console.error(`[skip] handler not found: ${handlerPath}`);
+ continue;
+ }
+ console.log(`\n# ${handlerPath}`);
+ for (const c of cases) {
+ const r = runOne(handlerPath, c);
+ if (r.fails.length === 0) {
+ console.log(` ok ${c.name}`);
+ } else {
+ failed++;
+ console.error(` fail ${c.name}`);
+ for (const f of r.fails) console.error(` - ${f}`);
+ if (r.out.trim()) console.error(` stdout: ${r.out.trim().replace(/\n/g, ' | ')}`);
+ if (r.err.trim()) console.error(` stderr: ${r.err.trim().replace(/\n/g, ' | ')}`);
+ }
+ }
+}
+
+if (failed > 0) {
+ console.error(`\n${failed} pre-bash smoke case(s) failed β€” regression of #2017`);
+ process.exit(1);
+}
+console.log('\nok: pre-bash hook gates dangerous commands across both handler copies');
diff --git a/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs b/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs
index c8a7668d17..7d1bf7f65a 100644
--- a/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs
+++ b/v3/@claude-flow/cli/.claude/helpers/hook-handler.cjs
@@ -148,8 +148,12 @@ const handlers = {
},
'pre-bash': () => {
- // Basic command safety check β€” prefer stdin command data from Claude Code
- const cmd = (hookInput.command || prompt).toLowerCase();
+ // Basic command safety check β€” prefer stdin command data from Claude Code.
+ // String() wrap is belt-and-suspenders for #2017: even if a future regression
+ // re-binds `prompt` or `hookInput.command` to a non-string, `.toLowerCase()`
+ // can no longer throw a TypeError that the global try/catch would swallow
+ // (silently exiting 0 and letting the dangerous command through).
+ const cmd = String(hookInput.command || toolInput.command || prompt || '').toLowerCase();
const dangerous = ['rm -rf /', 'format c:', 'del /s /q c:\\', ':(){:|:&};:'];
for (const d of dangerous) {
if (cmd.includes(d)) {
diff --git a/v3/@claude-flow/cli/package.json b/v3/@claude-flow/cli/package.json
index 426e556101..59b4a2831e 100644
--- a/v3/@claude-flow/cli/package.json
+++ b/v3/@claude-flow/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@claude-flow/cli",
- "version": "3.7.0-alpha.39",
+ "version": "3.7.0-alpha.40",
"type": "module",
"description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
"main": "dist/src/index.js",