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(mcp): absent URL assertions use the configured base; loopback HTTP in operator config

ruv39d73ea1eba7
diff --git a/v3/@claude-flow/cli/__tests__/mcp-service-url-security.test.ts b/v3/@claude-flow/cli/__tests__/mcp-service-url-security.test.ts
index ed321d9800..e50b30c13a 100644
--- a/v3/@claude-flow/cli/__tests__/mcp-service-url-security.test.ts
+++ b/v3/@claude-flow/cli/__tests__/mcp-service-url-security.test.ts
@@ -33,7 +33,7 @@ describe('MCP service destinations are operator-controlled', () => {
await expect(call('seraphina_guidance', { goal: 'test', [field]: 'https://attacker.example' })).rejects.toThrow(/configured/);
expect(fetch).not.toHaveBeenCalled();
});
- it.each(['http://127.0.0.1:19999', 'http://169.254.169.254', 'file:///etc/passwd', 'https://[email protected]', 'https://trusted-gateway.example:444', 'https://trusted-gateway.example/other', 'https://trusted-gateway.example?x=1', 'https://trusted-gateway.example#x', {}, null])('rejects hostile or malformed override %j', async gatewayUrl => {
+ it.each(['http://127.0.0.1:19999', 'http://169.254.169.254', 'file:///etc/passwd', 'https://[email protected]', 'https://trusted-gateway.example:444', 'https://trusted-gateway.example/other', 'https://trusted-gateway.example?x=1', 'https://trusted-gateway.example#x', {}, 0, false])('rejects hostile or malformed override %j', async gatewayUrl => {
await expect(call('x_federation_publish', { gatewayUrl, msgType: 'Status', payload: {} })).rejects.toThrow();
expect(fetch).not.toHaveBeenCalled();
});
@@ -51,11 +51,23 @@ describe('MCP service destinations are operator-controlled', () => {
expect(fetch).toHaveBeenLastCalledWith('https://trusted-llm.example/v1/messages', expect.objectContaining({ headers: expect.objectContaining({ 'x-api-key': 'SYNTHETIC-LLM-CANARY' }) }));
expect(JSON.parse(String(vi.mocked(fetch).mock.calls.at(-1)![1]!.body)).model).toBe('cognitum-high');
});
- it.each(['http://public.example', 'http://localhost:19999', 'file:///tmp/test', 'https://user:[email protected]', 'https://trusted.example?x=1', 'https://trusted.example#x'])('rejects unsafe operator configuration %s', async value => {
+ it.each(['http://public.example', 'http://localhost.attacker.example', 'http://127.0.0.1.nip.io', 'http://10.0.0.1', 'file:///tmp/test', 'https://user:[email protected]', 'https://trusted.example?x=1', 'https://trusted.example#x'])('rejects unsafe operator configuration %s', async value => {
vi.stubEnv('RUFLO_X_GATEWAY_URL', value);
await expect(call('x_federation_sync')).rejects.toThrow();
expect(fetch).not.toHaveBeenCalled();
});
+ it.each([undefined, null, ''])('an absent override (%j) asserts nothing: the configured gateway is used', async gatewayUrl => {
+ await call('x_federation_sync', { gatewayUrl });
+ expect(fetch).toHaveBeenCalledWith('https://trusted-gateway.example/mcp', expect.objectContaining({ redirect: 'error' }));
+ });
+ it('operator config may name a loopback HTTP service; a matching assertion passes, another port does not', async () => {
+ vi.stubEnv('RUFLO_X_GATEWAY_URL', 'http://localhost:8080');
+ await call('x_federation_sync', { gatewayUrl: 'http://localhost:8080/' });
+ expect(fetch).toHaveBeenCalledWith('http://localhost:8080/mcp', expect.anything());
+ vi.mocked(fetch).mockClear();
+ await expect(call('x_federation_publish', { gatewayUrl: 'http://localhost:9999', msgType: 'Status', payload: {} })).rejects.toThrow(/must match/);
+ expect(fetch).not.toHaveBeenCalled();
+ });
it('validates the LLM configuration before any gateway fetch', async () => {
vi.stubEnv('SERAPHINA_METALLM_URL', 'http://public.example');
await expect(call('seraphina_guidance', { goal: 'test' })).rejects.toThrow();
diff --git a/v3/@claude-flow/cli/src/mcp-tools/service-url.ts b/v3/@claude-flow/cli/src/mcp-tools/service-url.ts
index 50e0d5a814..b76b5c6ba2 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/service-url.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/service-url.ts
@@ -3,6 +3,8 @@
* Retain URL arguments as compatibility assertions against trusted process config.
* Exact base matching also prevents caller-selected paths on a trusted origin.
*/
+const LOOPBACK = new Set(['localhost', '127.0.0.1', '[::1]']);
+
export function configuredServiceUrl(configured: string, override: unknown, setting: string): string {
const normalize = (value: unknown): string => {
if (typeof value !== 'string' || !value || value !== value.trim()) {
@@ -11,13 +13,17 @@ export function configuredServiceUrl(configured: string, override: unknown, sett
let url: URL;
try { url = new URL(value); }
catch { throw new Error(`${setting}: expected a configured HTTPS base URL`); }
- if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash) {
- throw new Error(`${setting}: configured base URL must use HTTPS without credentials, query or fragment`);
+ // Plain HTTP only for a loopback service (a local or self-hosted gateway or LLM). An argument
+ // must equal the configured base exactly, so it can never pick a loopback port the operator did not.
+ const isLocalHttp = url.protocol === 'http:' && LOOPBACK.has(url.hostname);
+ if ((url.protocol !== 'https:' && !isLocalHttp) || url.username || url.password || url.search || url.hash) {
+ throw new Error(`${setting}: configured base URL must use HTTPS (or HTTP on loopback) without credentials, query or fragment`);
}
return url.href.replace(/\/+$/, '');
};
const base = normalize(configured);
- if (override !== undefined && normalize(override) !== base) {
+ // An absent, null or empty argument asserts nothing: use the configured base.
+ if (override !== undefined && override !== null && override !== '' && normalize(override) !== base) {
throw new Error(`${setting}: tool URL must match the configured service; configure the MCP server environment to change destinations`);
}
return base;