Merge pull request #4945 from ruvnet/fix/socket-alerts-ruflo-tarball

fix(ruflo): ship the wrapper only, harden the bridge's outbound guard; release 3.75.2
This commit is contained in:
rUv authored and GitHub committed 2026-11-10 12:33:43 -05:00
commit 5b70d2b545
20 files changed
+438 -99

No files matched your search

@@ -35,6 +35,8 @@ jobs:
node-version: 22
- name: ADR-166 §6 #9 — anti-regression lock (both bridges)
run: node ruflo/src/mcp-bridge/test-security-lock.js
- name: Outbound URL guard (both bridges)
run: node ruflo/src/mcp-bridge/test-url-guard.mjs
runtime-behavior:
name: Runtime behavior — 401 + terminal gate + fail-closed
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "claude-flow",
"version": "3.75.1",
"version": "3.75.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "claude-flow",
"version": "3.75.1",
"version": "3.75.2",
"bundleDependencies": [
"@claude-flow/codex",
"@claude-flow/mcp",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "claude-flow",
"version": "3.75.1",
"version": "3.75.2",
"workspaces": [
"v3/@claude-flow/codex",
"v3/@claude-flow/mcp",
@@ -1,7 +1,7 @@
# ADR-032: RVF Private Network MCP Tunnel
## Status
Implemented
Implemented, then the build-time patch was removed (2026-11-10). The `sed` patterns no longer match the upstream image, so the script had become a silent no-op, and where it did match it relaxed the check for every URL, not only operator-configured ones. The ruvocal fork implements the same allowance in source (`isAllowedMcpUrl`, `allowPrivate` for `MCP_SERVERS` entries only).
## Context
HuggingFace Chat UI enforces HTTPS-only for MCP server URLs as SSRF protection (`urlSafety.isValidUrl()`). In containerized deployments (Docker Compose), the MCP bridge runs on a private Docker network (`http://mcp-bridge:3001/mcp`) — not exposed to the internet.
+2 -3
View File
@@ -1,7 +1,7 @@
{
"name": "ruflo",
"mcpName": "io.github.ruvnet/ruflo",
"version": "3.75.1",
"version": "3.75.2",
"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",
@@ -19,7 +19,6 @@
},
"files": [
"bin/**",
"src/**",
"dist/**",
"README.md",
"LICENSE"
@@ -41,7 +40,7 @@
"package:rvf": "bash src/scripts/package-rvf.sh"
},
"dependencies": {
"@claude-flow/cli": "3.75.1"
"@claude-flow/cli": "3.75.2"
},
"optionalDependencies": {},
"overrides": {
-1
View File
@@ -202,7 +202,6 @@
"private_tunnel": {
"protocol": "http",
"scope": "docker-network-only",
"patch": "chat-ui/patch-mcp-url-safety.sh",
"adr": "docs/adr/ADR-032-RVF-PRIVATE-MCP-TUNNEL.md"
},
"env_only_keys": [
+2 -2
View File
@@ -9,12 +9,12 @@
"subfolder": "ruflo"
},
"websiteUrl": "https://github.com/ruvnet/ruflo",
"version": "3.75.1",
"version": "3.75.2",
"packages": [
{
"registryType": "npm",
"identifier": "ruflo",
"version": "3.75.1",
"version": "3.75.2",
"runtimeHint": "npx",
"transport": {
"type": "stdio"
-7
View File
@@ -6,13 +6,6 @@ USER root
# Bake .env.local with MODELS config (too large for Cloud Run env vars)
COPY dotenv-local.txt /app/.env.local
# RVF Security Patch — allow private Docker network MCP connections.
# HF Chat UI enforces HTTPS for MCP URLs (SSRF protection).
# In containerized deployments, MCP bridge runs on private Docker network.
# This patch allows HTTP for admin-configured MCP_SERVERS only.
COPY patch-mcp-url-safety.sh /tmp/patch-mcp-url-safety.sh
RUN sh /tmp/patch-mcp-url-safety.sh && rm /tmp/patch-mcp-url-safety.sh
# Copy branded welcome GIF into the SvelteKit static asset directory.
COPY static/chatui/omni-welcome.gif /app/build/client/chatui/omni-welcome.gif
COPY static/chatui/omni-welcome.gif /app/static/chatui/omni-welcome.gif
-28
View File
@@ -1,28 +0,0 @@
#!/bin/sh
# RVF Security Patch — Allow private network MCP connections
#
# HF Chat UI enforces HTTPS-only for MCP server URLs to prevent SSRF.
# In containerized deployments, MCP servers run on the private Docker
# network (not exposed to the internet). This patch allows HTTP for
# admin-configured MCP_SERVERS URLs while maintaining SSRF protection
# for user-provided URLs.
#
# Security model:
# - MCP_SERVERS is set by the deployment admin (env var / .env.local)
# - Private Docker network is not accessible from the internet
# - The patch only relaxes protocol check, not IP safety checks
URLSAFETY_FILE=$(find /app/build/server -name "urlSafety-*.js" | head -1)
if [ -z "$URLSAFETY_FILE" ]; then
echo "[rvf-patch] urlSafety file not found, skipping"
exit 0
fi
# Allow http: protocol in addition to https:
sed -i 's/if (url\.protocol !== "https:")/if (url.protocol !== "https:" \&\& url.protocol !== "http:")/' "$URLSAFETY_FILE"
# Allow localhost for container-internal MCP servers
sed -i 's/if (hostname === "localhost")/if (false \&\& hostname === "localhost")/' "$URLSAFETY_FILE"
echo "[rvf-patch] Patched $URLSAFETY_FILE for private network MCP"
+3 -2
View File
@@ -11,12 +11,13 @@ RUN npm install --production
# Each installed separately so one failure doesn't block others
RUN npm install -g ruvector || true
RUN npm install -g ruflo || true
RUN npm install -g agentic-flow@alpha || true
RUN npm install -g gemini-mcp-server || true
RUN npm install -g agentic-flow@3.0.0-alpha.2 || true
RUN npm install -g gemini-mcp-server@1.2.2 || true
RUN npm install -g @openai/codex || true
COPY index.js ./
COPY mcp-stdio-kernel.js ./
COPY url-guard.js ./
# Create writable directories for MCP backends (ruflo, ruvector, agentic-flow)
# These tools write state/tasks/memory to the working directory at runtime
+32 -24
View File
@@ -1,6 +1,7 @@
import express from "express";
import { spawn } from "child_process";
import { randomUUID, timingSafeEqual } from "crypto";
import { assertPublicUrl } from "./url-guard.js";
// =============================================================================
// CONFIGURATION
@@ -84,7 +85,7 @@ const TOOL_GROUPS = {
prefixes: ["neural_", "daa_"],
},
// --- Agentic Flow (agentic-flow@alpha) ---
// --- Agentic Flow (agentic-flow, pinned in BACKEND_VERSIONS) ---
"agentic-flow": {
enabled: process.env.MCP_GROUP_AGENTIC_FLOW === "true",
description: "Execute 66+ specialized agents, batch code editing, AgentDB patterns (agentic-flow)",
@@ -122,6 +123,15 @@ if (process.env.MCP_GROUP_CODEX === "true") {
// STDIO MCP CLIENT — Connects to external MCP servers via child process
// =============================================================================
// Backends inherit the provider keys they need, but not the bridge's own
// bearer token: a backend has no use for it, and holding it would let a
// compromised backend call the bridge as an authenticated client.
function backendEnv() {
const env = { ...process.env };
delete env.MCP_AUTH_TOKEN;
return env;
}
class StdioMcpClient {
constructor(name, command, args = []) {
this.name = name;
@@ -139,7 +149,7 @@ class StdioMcpClient {
try {
this.process = spawn(this.command, this.args, {
stdio: ["pipe", "pipe", "pipe"],
env: { ...process.env },
env: backendEnv(),
});
this.process.stdout.on("data", (data) => this._onData(data.toString()));
@@ -255,12 +265,21 @@ class StdioMcpClient {
// BACKEND REGISTRY
// =============================================================================
// Exact versions for backends that are third-party or were tracking a
// pre-release tag, so a new upload cannot change what the bridge executes.
// ruvector and ruflo are first-party and follow `latest`. Keep these in step
// with the Dockerfile's pre-install lines.
const BACKEND_VERSIONS = {
"agentic-flow": "3.0.0-alpha.2", // what the `alpha` tag resolved to; 3.5.3 drops tools the help text lists
"gemini-mcp-server": "1.2.2",
};
const BACKEND_DEFS = [
{ name: "ruvector", command: "npx", args: ["-y", "ruvector", "mcp", "start"], groups: ["intelligence"] },
{ name: "ruflo", command: "npx", args: ["-y", "ruflo", "mcp", "start"], groups: ["agents", "memory", "devtools", "security", "browser", "neural"] },
{ name: "agentic-flow", command: "npx", args: ["-y", "agentic-flow@alpha", "mcp", "start"], groups: ["agentic-flow"] },
{ name: "agentic-flow", command: "npx", args: ["-y", `agentic-flow@${BACKEND_VERSIONS["agentic-flow"]}`, "mcp", "start"], groups: ["agentic-flow"] },
{ name: "claude", command: "claude", args: ["mcp", "serve"], groups: ["claude-code"] },
{ name: "gemini-mcp", command: "npx", args: ["-y", "gemini-mcp-server"], groups: ["gemini"] },
{ name: "gemini-mcp", command: "npx", args: ["-y", `gemini-mcp-server@${BACKEND_VERSIONS["gemini-mcp-server"]}`], groups: ["gemini"] },
];
const mcpBackends = new Map();
@@ -554,7 +573,7 @@ Neural network operations and Decentralized Autonomous Agents.
- Autonomous agent workflows
- Knowledge transfer between agents`,
"agentic-flow": `# Agentic Flow Group (agentic-flow@alpha)
"agentic-flow": `# Agentic Flow Group (agentic-flow)
Execute 66+ specialized agents with boosted code editing and AgentDB.
@@ -635,36 +654,25 @@ Unavailable: current Codex CLI has no MCP server mode (#3509). This group is dis
// SSRF GUARD — Reject requests to private/loopback ranges (CWE-918)
// =============================================================================
const PRIVATE_IP_RE = /^(?:10\.|172\.(?:1[6-9]|2\d|3[01])\.|192\.168\.|127\.|0\.|::1|fc|fd)/i;
function assertSafeUrl(rawUrl) {
let parsed;
try {
parsed = new URL(rawUrl);
} catch {
throw new Error(`SSRF guard: invalid URL — ${rawUrl}`);
}
if (parsed.protocol !== "https:") {
throw new Error(`SSRF guard: only HTTPS URLs are permitted, got ${parsed.protocol}`);
}
const host = parsed.hostname;
if (PRIVATE_IP_RE.test(host) || host === "localhost" || host.endsWith(".local")) {
throw new Error(`SSRF guard: private/loopback host rejected — ${host}`);
}
}
// Implemented in ./url-guard.js so it can be unit-tested (test-url-guard.mjs).
// =============================================================================
// HELPER — Call a backend Cloud Function / API
// =============================================================================
async function callCloudFunction(url, payload, timeoutMs = 25000) {
// Validate the URL before making any network request.
assertSafeUrl(url);
// Validate the URL, and what it resolves to, before any network request.
try {
await assertPublicUrl(url);
} catch (err) {
return { error: err.message };
}
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeoutMs);
try {
const resp = await fetch(url, {
method: "POST",
redirect: "error", // a redirect could point somewhere the guard never saw
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
signal: controller.signal,
@@ -73,6 +73,16 @@ const CHECKS = [
rx: /Mcp-Session-Id/,
hint: "Mcp-Session-Id header must be echoed on /mcp* responses (#2425)",
},
{
id: "10. outbound-url-guard-resolves-dns",
rx: /import\s*\{\s*assertPublicUrl\s*\}\s*from\s*["']\.\/url-guard\.js["'][\s\S]*?async function callCloudFunction[\s\S]*?await assertPublicUrl\(url\)[\s\S]*?redirect:\s*["']error["']/,
hint: "callCloudFunction must await assertPublicUrl (./url-guard.js) and refuse redirects",
},
{
id: "11. backends-do-not-inherit-bridge-token",
rx: /delete env\.MCP_AUTH_TOKEN[\s\S]*?env:\s*backendEnv\(\)/,
hint: "spawned backends must not receive MCP_AUTH_TOKEN",
},
];
let hardFail = false;
@@ -85,6 +95,14 @@ for (const bridge of BRIDGES) {
const src = fs.readFileSync(bridge, "utf-8");
const rel = path.relative(path.join(HERE, "..", ".."), bridge);
console.log(`\n# ${rel}`);
const tagged = src.match(/["'`][\w@/.-]+@(?:alpha|beta|next|latest|canary)["'`]/g);
if (tagged) {
console.log(` ✗ 12. no-dist-tag-backend-specs: ${tagged.join(", ")}`);
console.log(" hint: a backend spec must be a bare first-party name or an exact version, never a moving dist-tag");
hardFail = true;
} else {
console.log(" ✓ 12. no-dist-tag-backend-specs");
}
for (const check of CHECKS) {
if (check.rx.test(src)) {
console.log(` ✓ ${check.id}`);
@@ -105,6 +123,13 @@ for (const dockerfile of DOCKERFILES) {
const source = fs.readFileSync(dockerfile, "utf-8");
const rel = path.relative(path.join(HERE, "..", ".."), dockerfile);
console.log(`\n# ${rel}`);
if (/^COPY\s+url-guard\.js\s/m.test(source)) {
console.log(" ✓ 13. image-includes-url-guard");
} else {
console.log(" ✗ 13. image-includes-url-guard");
console.log(" hint: the image must COPY url-guard.js or the bridge fails to start");
hardFail = true;
}
if (/^FROM\s+node:24(?:[.-][^\s]+)?\s*$/m.test(source)) {
console.log(" ✓ 9. supported-node-lts-runtime (#2847)");
} else {
+112
View File
@@ -0,0 +1,112 @@
#!/usr/bin/env node
// SSRF guard tests for both bridge copies. Run: node test-url-guard.mjs
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const COPIES = [
path.join(HERE, "url-guard.js"),
path.join(HERE, "..", "ruvocal", "mcp-bridge", "url-guard.js"),
];
assert.equal(
fs.readFileSync(COPIES[0], "utf8"),
fs.readFileSync(COPIES[1], "utf8"),
"the two url-guard.js copies must be byte-identical",
);
const REJECTED = [
"http://example.com/", // not HTTPS
"file:///etc/passwd",
"not a url",
"https://localhost/",
"https://LOCALHOST./", // case and trailing dot
"https://api.localhost/",
"https://printer.local/",
"https://metadata.google.internal/",
"https://mcp-bridge/", // dotless Docker service name
"https://127.0.0.1/",
"https://2130706433/", // 127.0.0.1 as a decimal integer
"https://0x7f.1/", // 127.0.0.1 in hex shorthand
"https://0.0.0.0/",
"https://10.1.2.3/",
"https://172.16.0.1/",
"https://172.31.255.255/",
"https://192.168.1.1/",
"https://169.254.169.254/latest/meta-data/", // cloud metadata
"https://100.64.0.1/", // carrier-grade NAT
"https://224.0.0.1/",
"https://255.255.255.255/",
"https://[::1]/",
"https://[::]/",
"https://[::ffff:127.0.0.1]/", // IPv4-mapped loopback
"https://[::ffff:169.254.169.254]/",
"https://[fc00::1]/",
"https://[fd12:3456::1]/",
"https://[fe80::1]/",
"https://[64:ff9b::7f00:1]/", // NAT64 of 127.0.0.1
];
const ACCEPTED = [
"https://example.com/path?x=1",
"https://us-central1-proj.cloudfunctions.net/search",
"https://fcc.gov/", // the old regex refused any host starting "fc"/"fd"
"https://fda.gov/",
"https://172.15.0.1/", // just outside 172.16/12
"https://172.32.0.1/",
"https://8.8.8.8/",
"https://[2606:4700:4700::1111]/",
];
let failures = 0;
const check = (name, fn) => {
try { fn(); console.log(` ✓ ${name}`); }
catch (err) { failures++; console.log(` ✗ ${name}\n ${err.message}`); }
};
const checkAsync = async (name, fn) => {
try { await fn(); console.log(` ✓ ${name}`); }
catch (err) { failures++; console.log(` ✗ ${name}\n ${err.message}`); }
};
for (const file of COPIES) {
console.log(`\n# ${path.relative(path.join(HERE, "..", ".."), file)}`);
const { assertSafeUrl, assertPublicUrl, isBlockedAddress } = await import(pathToFileURL(file).href);
for (const url of REJECTED) {
check(`rejects ${url}`, () => assert.throws(() => assertSafeUrl(url), /SSRF guard/));
}
for (const url of ACCEPTED) {
check(`accepts ${url}`, () => assert.doesNotThrow(() => assertSafeUrl(url)));
}
check("an invalid-URL error does not echo the input", () => {
assert.throws(() => assertSafeUrl("https://user:secret@"), (err) => !err.message.includes("secret"));
});
check("a non-IP string is treated as blocked", () => assert.equal(isBlockedAddress("example.com"), true));
const resolvesTo = (...addresses) => async () => addresses.map((address) => ({ address }));
await checkAsync("refuses a public name that resolves to loopback", () =>
assert.rejects(assertPublicUrl("https://rebind.example.com/", resolvesTo("127.0.0.1")), /resolves to a private/));
await checkAsync("refuses when any one resolved address is private", () =>
assert.rejects(assertPublicUrl("https://rebind.example.com/", resolvesTo("93.184.216.34", "10.0.0.5")), /resolves to a private/));
await checkAsync("refuses a name that resolves to the metadata address over IPv6-mapped IPv4", () =>
assert.rejects(assertPublicUrl("https://rebind.example.com/", resolvesTo("::ffff:169.254.169.254")), /resolves to a private/));
await checkAsync("refuses a name that does not resolve", () =>
assert.rejects(assertPublicUrl("https://nothing.example.com/", resolvesTo()), /did not resolve/));
await checkAsync("accepts a name that resolves only to public addresses", async () => {
const parsed = await assertPublicUrl("https://ok.example.com/x", resolvesTo("93.184.216.34", "2606:4700:4700::1111"));
assert.equal(parsed.hostname, "ok.example.com");
});
await checkAsync("does not resolve an IP literal", async () => {
await assertPublicUrl("https://8.8.8.8/", async () => { throw new Error("lookup must not be called"); });
});
await checkAsync("rejects before resolving when the URL itself is unsafe", () =>
assert.rejects(assertPublicUrl("http://example.com/", async () => { throw new Error("lookup must not be called"); }), /only HTTPS/));
}
if (failures) {
console.error(`\n${failures} check(s) failed`);
process.exit(1);
}
console.log("\nurl-guard: all checks passed");
+94
View File
@@ -0,0 +1,94 @@
// SSRF guard for the bridge's outbound calls (CWE-918).
//
// Only public HTTPS endpoints pass. The hostname is checked as written and,
// in assertPublicUrl, again after DNS resolution, so a public name that
// resolves to a private address is refused too.
//
// This file exists twice (src/mcp-bridge and src/ruvocal/mcp-bridge) and the
// copies must stay byte-identical; test-url-guard.mjs fails if they drift.
import { BlockList, isIP } from "node:net";
import { lookup as dnsLookup } from "node:dns/promises";
const BLOCKED = new BlockList();
for (const [net, prefix] of [
["0.0.0.0", 8], // "this network"
["10.0.0.0", 8], // private
["100.64.0.0", 10], // carrier-grade NAT
["127.0.0.0", 8], // loopback
["169.254.0.0", 16], // link-local, cloud metadata
["172.16.0.0", 12], // private
["192.0.0.0", 24], // IETF protocol assignments
["192.168.0.0", 16], // private
["198.18.0.0", 15], // benchmarking
["224.0.0.0", 4], // multicast
["240.0.0.0", 4], // reserved, broadcast
]) BLOCKED.addSubnet(net, prefix, "ipv4");
for (const [net, prefix] of [
["::", 128], // unspecified
["::1", 128], // loopback
["64:ff9b::", 96], // NAT64, maps onto IPv4
["fc00::", 7], // unique-local
["fe80::", 10], // link-local
["ff00::", 8], // multicast
]) BLOCKED.addSubnet(net, prefix, "ipv6");
/** True when an IP literal is loopback, private, link-local or otherwise not public. */
export function isBlockedAddress(address) {
const family = isIP(address);
if (family === 4) return BLOCKED.check(address, "ipv4");
// An IPv4-mapped IPv6 address is matched against the IPv4 rules as well.
if (family === 6) return BLOCKED.check(address, "ipv6");
return true; // not an IP literal: refuse instead of guessing
}
function bareHostname(parsed) {
return parsed.hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
}
/** Synchronous check of the URL as written. Throws on anything not public HTTPS. */
export function assertSafeUrl(rawUrl) {
let parsed;
try {
parsed = new URL(rawUrl);
} catch {
throw new Error("SSRF guard: invalid URL");
}
if (parsed.protocol !== "https:") {
throw new Error(`SSRF guard: only HTTPS URLs are permitted, got ${parsed.protocol}`);
}
const host = bareHostname(parsed);
if (isIP(host)) {
if (isBlockedAddress(host)) {
throw new Error(`SSRF guard: private/loopback address rejected — ${host}`);
}
return parsed;
}
if (
!host.includes(".") ||
host === "localhost" ||
host.endsWith(".localhost") ||
host.endsWith(".local") ||
host.endsWith(".internal")
) {
throw new Error(`SSRF guard: private/loopback host rejected — ${host}`);
}
return parsed;
}
/**
* assertSafeUrl plus a check of every address the hostname resolves to.
* `lookup` is injectable for tests.
*/
export async function assertPublicUrl(rawUrl, lookup = dnsLookup) {
const parsed = assertSafeUrl(rawUrl);
const host = bareHostname(parsed);
if (isIP(host)) return parsed;
const addresses = await lookup(host, { all: true });
if (!addresses.length) throw new Error(`SSRF guard: ${host} did not resolve`);
for (const { address } of addresses) {
if (isBlockedAddress(address)) {
throw new Error(`SSRF guard: ${host} resolves to a private/loopback address (${address})`);
}
}
return parsed;
}
+3 -2
View File
@@ -11,12 +11,13 @@ RUN npm install --production
# Each installed separately so one failure doesn't block others
RUN npm install -g ruvector || true
RUN npm install -g ruflo || true
RUN npm install -g agentic-flow@alpha || true
RUN npm install -g gemini-mcp-server || true
RUN npm install -g agentic-flow@3.0.0-alpha.2 || true
RUN npm install -g gemini-mcp-server@1.2.2 || true
RUN npm install -g @openai/codex || true
COPY index.js ./
COPY mcp-stdio-kernel.js ./
COPY url-guard.js ./
# Create writable directories for MCP backends (ruflo, ruvector, agentic-flow)
# These tools write state/tasks/memory to the working directory at runtime
+32 -24
View File
@@ -1,6 +1,7 @@
import express from "express";
import { spawn } from "child_process";
import { randomUUID, timingSafeEqual } from "crypto";
import { assertPublicUrl } from "./url-guard.js";
// =============================================================================
// CONFIGURATION
@@ -84,7 +85,7 @@ const TOOL_GROUPS = {
prefixes: ["neural_", "daa_"],
},
// --- Agentic Flow (agentic-flow@alpha) ---
// --- Agentic Flow (agentic-flow, pinned in BACKEND_VERSIONS) ---
"agentic-flow": {
enabled: process.env.MCP_GROUP_AGENTIC_FLOW === "true",
description: "Execute 66+ specialized agents, batch code editing, AgentDB patterns (agentic-flow)",
@@ -122,6 +123,15 @@ if (process.env.MCP_GROUP_CODEX === "true") {
// STDIO MCP CLIENT — Connects to external MCP servers via child process
// =============================================================================
// Backends inherit the provider keys they need, but not the bridge's own
// bearer token: a backend has no use for it, and holding it would let a
// compromised backend call the bridge as an authenticated client.
function backendEnv() {
const env = { ...process.env };
delete env.MCP_AUTH_TOKEN;
return env;
}
class StdioMcpClient {
constructor(name, command, args = []) {
this.name = name;
@@ -139,7 +149,7 @@ class StdioMcpClient {
try {
this.process = spawn(this.command, this.args, {
stdio: ["pipe", "pipe", "pipe"],
env: { ...process.env },
env: backendEnv(),
});
this.process.stdout.on("data", (data) => this._onData(data.toString()));
@@ -260,12 +270,21 @@ class StdioMcpClient {
// BACKEND REGISTRY
// =============================================================================
// Exact versions for backends that are third-party or were tracking a
// pre-release tag, so a new upload cannot change what the bridge executes.
// ruvector and ruflo are first-party and follow `latest`. Keep these in step
// with the Dockerfile's pre-install lines.
const BACKEND_VERSIONS = {
"agentic-flow": "3.0.0-alpha.2", // what the `alpha` tag resolved to; 3.5.3 drops tools the help text lists
"gemini-mcp-server": "1.2.2",
};
const BACKEND_DEFS = [
{ name: "ruvector", command: "npx", args: ["-y", "ruvector", "mcp", "start"], groups: ["intelligence"] },
{ name: "ruflo", command: "npx", args: ["-y", "ruflo", "mcp", "start"], groups: ["agents", "memory", "devtools", "security", "browser", "neural"] },
{ name: "agentic-flow", command: "npx", args: ["-y", "agentic-flow@alpha", "mcp", "start"], groups: ["agentic-flow"] },
{ name: "agentic-flow", command: "npx", args: ["-y", `agentic-flow@${BACKEND_VERSIONS["agentic-flow"]}`, "mcp", "start"], groups: ["agentic-flow"] },
{ name: "claude", command: "claude", args: ["mcp", "serve"], groups: ["claude-code"] },
{ name: "gemini-mcp", command: "npx", args: ["-y", "gemini-mcp-server"], groups: ["gemini"] },
{ name: "gemini-mcp", command: "npx", args: ["-y", `gemini-mcp-server@${BACKEND_VERSIONS["gemini-mcp-server"]}`], groups: ["gemini"] },
];
const mcpBackends = new Map();
@@ -559,7 +578,7 @@ Neural network operations and Decentralized Autonomous Agents.
- Autonomous agent workflows
- Knowledge transfer between agents`,
"agentic-flow": `# Agentic Flow Group (agentic-flow@alpha)
"agentic-flow": `# Agentic Flow Group (agentic-flow)
Execute 66+ specialized agents with boosted code editing and AgentDB.
@@ -724,36 +743,25 @@ async function geminiGroundedSearch(query, mode = "search") {
// SSRF GUARD — Reject requests to private/loopback ranges (CWE-918)
// =============================================================================
const PRIVATE_IP_RE = /^(?:10\.|172\.(?:1[6-9]|2\d|3[01])\.|192\.168\.|127\.|0\.|::1|fc|fd)/i;
function assertSafeUrl(rawUrl) {
let parsed;
try {
parsed = new URL(rawUrl);
} catch {
throw new Error(`SSRF guard: invalid URL — ${rawUrl}`);
}
if (parsed.protocol !== "https:") {
throw new Error(`SSRF guard: only HTTPS URLs are permitted, got ${parsed.protocol}`);
}
const host = parsed.hostname;
if (PRIVATE_IP_RE.test(host) || host === "localhost" || host.endsWith(".local")) {
throw new Error(`SSRF guard: private/loopback host rejected — ${host}`);
}
}
// Implemented in ./url-guard.js so it can be unit-tested (test-url-guard.mjs).
// =============================================================================
// HELPER — Call a backend Cloud Function / API
// =============================================================================
async function callCloudFunction(url, payload, timeoutMs = 25000) {
// Validate the URL before making any network request.
assertSafeUrl(url);
// Validate the URL, and what it resolves to, before any network request.
try {
await assertPublicUrl(url);
} catch (err) {
return { error: err.message };
}
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeoutMs);
try {
const resp = await fetch(url, {
method: "POST",
redirect: "error", // a redirect could point somewhere the guard never saw
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
signal: controller.signal,
+94
View File
@@ -0,0 +1,94 @@
// SSRF guard for the bridge's outbound calls (CWE-918).
//
// Only public HTTPS endpoints pass. The hostname is checked as written and,
// in assertPublicUrl, again after DNS resolution, so a public name that
// resolves to a private address is refused too.
//
// This file exists twice (src/mcp-bridge and src/ruvocal/mcp-bridge) and the
// copies must stay byte-identical; test-url-guard.mjs fails if they drift.
import { BlockList, isIP } from "node:net";
import { lookup as dnsLookup } from "node:dns/promises";
const BLOCKED = new BlockList();
for (const [net, prefix] of [
["0.0.0.0", 8], // "this network"
["10.0.0.0", 8], // private
["100.64.0.0", 10], // carrier-grade NAT
["127.0.0.0", 8], // loopback
["169.254.0.0", 16], // link-local, cloud metadata
["172.16.0.0", 12], // private
["192.0.0.0", 24], // IETF protocol assignments
["192.168.0.0", 16], // private
["198.18.0.0", 15], // benchmarking
["224.0.0.0", 4], // multicast
["240.0.0.0", 4], // reserved, broadcast
]) BLOCKED.addSubnet(net, prefix, "ipv4");
for (const [net, prefix] of [
["::", 128], // unspecified
["::1", 128], // loopback
["64:ff9b::", 96], // NAT64, maps onto IPv4
["fc00::", 7], // unique-local
["fe80::", 10], // link-local
["ff00::", 8], // multicast
]) BLOCKED.addSubnet(net, prefix, "ipv6");
/** True when an IP literal is loopback, private, link-local or otherwise not public. */
export function isBlockedAddress(address) {
const family = isIP(address);
if (family === 4) return BLOCKED.check(address, "ipv4");
// An IPv4-mapped IPv6 address is matched against the IPv4 rules as well.
if (family === 6) return BLOCKED.check(address, "ipv6");
return true; // not an IP literal: refuse instead of guessing
}
function bareHostname(parsed) {
return parsed.hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
}
/** Synchronous check of the URL as written. Throws on anything not public HTTPS. */
export function assertSafeUrl(rawUrl) {
let parsed;
try {
parsed = new URL(rawUrl);
} catch {
throw new Error("SSRF guard: invalid URL");
}
if (parsed.protocol !== "https:") {
throw new Error(`SSRF guard: only HTTPS URLs are permitted, got ${parsed.protocol}`);
}
const host = bareHostname(parsed);
if (isIP(host)) {
if (isBlockedAddress(host)) {
throw new Error(`SSRF guard: private/loopback address rejected — ${host}`);
}
return parsed;
}
if (
!host.includes(".") ||
host === "localhost" ||
host.endsWith(".localhost") ||
host.endsWith(".local") ||
host.endsWith(".internal")
) {
throw new Error(`SSRF guard: private/loopback host rejected — ${host}`);
}
return parsed;
}
/**
* assertSafeUrl plus a check of every address the hostname resolves to.
* `lookup` is injectable for tests.
*/
export async function assertPublicUrl(rawUrl, lookup = dnsLookup) {
const parsed = assertSafeUrl(rawUrl);
const host = bareHostname(parsed);
if (isIP(host)) return parsed;
const addresses = await lookup(host, { all: true });
if (!addresses.length) throw new Error(`SSRF guard: ${host} did not resolve`);
for (const { address } of addresses) {
if (isBlockedAddress(address)) {
throw new Error(`SSRF guard: ${host} resolves to a private/loopback address (${address})`);
}
}
return parsed;
}
+1 -1
View File
@@ -80,7 +80,7 @@ tar czf "$OUTPUT" \
mcp-bridge/package.json \
mcp-bridge/Dockerfile \
chat-ui/Dockerfile \
chat-ui/patch-mcp-url-safety.sh \
mcp-bridge/url-guard.js \
chat-ui/static/ \
mcp-bridge/mcp-stdio-kernel.js \
mcp-bridge/test-harness.js \
+31
View File
@@ -0,0 +1,31 @@
// The published `ruflo` package is the CLI wrapper only. The chat UI, the MCP
// bridge and the deploy scripts under src/ are built from the repo (Docker,
// Cloud Build) and nothing in bin/ reads them, so they stay out of the tarball.
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { dirname, resolve } from 'node:path';
import { test } from 'vitest';
import { fileURLToPath } from 'node:url';
const packageDir = resolve(dirname(fileURLToPath(import.meta.url)), '..');
function packedFiles() {
const out = execFileSync(
process.platform === 'win32' ? 'npm.cmd' : 'npm',
['pack', '--dry-run', '--json', '--ignore-scripts'],
{ cwd: packageDir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], shell: process.platform === 'win32' },
);
return JSON.parse(out)[0].files.map((f) => f.path);
}
test('the ruflo tarball ships the wrapper and nothing from src/', () => {
const files = packedFiles();
assert.ok(files.length > 0, 'npm pack listed no files');
assert.ok(files.includes('bin/ruflo.js'), 'bin/ruflo.js must ship');
assert.ok(files.includes('package.json'), 'package.json must ship');
const allowed = (p) => p.startsWith('bin/') || p.startsWith('dist/')
|| ['package.json', 'README.md', 'LICENSE'].includes(p);
const unexpected = files.filter((p) => !allowed(p));
assert.deepEqual(unexpected, [], `unexpected files in the ruflo tarball: ${unexpected.slice(0, 10).join(', ')}`);
});
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@claude-flow/cli",
"version": "3.75.1",
"version": "3.75.2",
"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",