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): rate-limit authenticated HTTP routes

ruv392e71912e1c
diff --git a/package-lock.json b/package-lock.json
index 7af26fdaa9..adea2c7629 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -36,6 +36,7 @@
"commander": "^12.0.0",
"cors": "^2.8.5",
"express": ">=4.22.2",
+ "express-rate-limit": ">=8.4.1",
"fast-uri": "3.1.5",
"fs-extra": "^11.2.0",
"helmet": "^7.2.0",
diff --git a/package.json b/package.json
index 6a74d9222f..4065db6e06 100644
--- a/package.json
+++ b/package.json
@@ -82,6 +82,7 @@
"cors": "^2.8.5",
"fs-extra": "^11.2.0",
"express": ">=4.22.2",
+ "express-rate-limit": ">=8.4.1",
"fast-uri": "3.1.5",
"helmet": "^7.2.0",
"inquirer": "^9.2.0",
diff --git a/v3/@claude-flow/cli/package.json b/v3/@claude-flow/cli/package.json
index e86d7b0fde..3b093cfd3d 100644
--- a/v3/@claude-flow/cli/package.json
+++ b/v3/@claude-flow/cli/package.json
@@ -114,6 +114,7 @@
"cors": "^2.8.5",
"fs-extra": "^11.2.0",
"express": ">=4.22.2",
+ "express-rate-limit": ">=8.4.1",
"fast-uri": "3.1.5",
"helmet": "^7.2.0",
"inquirer": "^9.2.0",
diff --git a/v3/@claude-flow/mcp/__tests__/integration.test.ts b/v3/@claude-flow/mcp/__tests__/integration.test.ts
index 99046db50f..9007295989 100644
--- a/v3/@claude-flow/mcp/__tests__/integration.test.ts
+++ b/v3/@claude-flow/mcp/__tests__/integration.test.ts
@@ -11,6 +11,7 @@ import {
definePrompt,
textMessage,
resourceMessage,
+ HttpTransport,
} from '../src/index.js';
import type { ILogger, MCPRequest, MCPResponse } from '../src/types.js';
@@ -447,3 +448,43 @@ describe('MCP 2025-11-25 Integration', () => {
});
});
});
+
+describe('HTTP transport security controls', () => {
+ it('rate-limits MCP requests while leaving health checks available', async () => {
+ const port = 41000 + Math.floor(Math.random() * 2000);
+ const transport = new HttpTransport(createMockLogger(), {
+ host: '127.0.0.1',
+ port,
+ corsEnabled: false,
+ rateLimit: { windowMs: 60_000, limit: 1 },
+ });
+ transport.onRequest(async (request) => ({
+ jsonrpc: '2.0',
+ id: request.id,
+ result: { ok: true },
+ }));
+
+ await transport.start();
+ try {
+ const request = {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'ping' }),
+ } as const;
+ const first = await fetch(`http://127.0.0.1:${port}/mcp`, request);
+ expect(first.status).toBe(200);
+
+ const limited = await fetch(`http://127.0.0.1:${port}/mcp`, request);
+ expect(limited.status).toBe(429);
+ expect(limited.headers.get('retry-after')).toBeTruthy();
+ await expect(limited.json()).resolves.toMatchObject({
+ error: { code: -32000, message: 'Rate limit exceeded' },
+ });
+
+ const health = await fetch(`http://127.0.0.1:${port}/health`);
+ expect(health.status).toBe(200);
+ } finally {
+ await transport.stop();
+ }
+ });
+});
diff --git a/v3/@claude-flow/mcp/package.json b/v3/@claude-flow/mcp/package.json
index d8125c66aa..2371270882 100644
--- a/v3/@claude-flow/mcp/package.json
+++ b/v3/@claude-flow/mcp/package.json
@@ -18,6 +18,7 @@
"ajv": "^8.12.0",
"cors": "^2.8.5",
"express": "^4.18.2",
+ "express-rate-limit": "^8.4.1",
"helmet": "^7.1.0",
"ws": "^8.14.2"
},
diff --git a/v3/@claude-flow/mcp/src/transport/http.ts b/v3/@claude-flow/mcp/src/transport/http.ts
index a01c2ac909..e9a611ea5d 100644
--- a/v3/@claude-flow/mcp/src/transport/http.ts
+++ b/v3/@claude-flow/mcp/src/transport/http.ts
@@ -10,6 +10,7 @@ import { createServer, Server } from 'http';
import { WebSocketServer, WebSocket } from 'ws';
import cors from 'cors';
import helmet from 'helmet';
+import { rateLimit } from 'express-rate-limit';
import { randomUUID } from 'crypto';
import type {
ITransport,
@@ -35,6 +36,10 @@ export interface HttpTransportConfig {
auth?: AuthConfig;
maxRequestSize?: string;
requestTimeout?: number;
+ rateLimit?: {
+ windowMs?: number;
+ limit?: number;
+ };
}
export class HttpTransport extends EventEmitter implements ITransport {
@@ -217,6 +222,20 @@ export class HttpTransport extends EventEmitter implements ITransport {
limit: this.config.maxRequestSize || '10mb',
}));
+ // Bound authenticated and unauthenticated RPC traffic before route-level
+ // authorization or request dispatch can consume significant resources.
+ this.app.use(['/rpc', '/mcp'], rateLimit({
+ windowMs: this.config.rateLimit?.windowMs ?? 60_000,
+ limit: this.config.rateLimit?.limit ?? 120,
+ standardHeaders: 'draft-7',
+ legacyHeaders: false,
+ message: {
+ jsonrpc: '2.0',
+ id: null,
+ error: { code: -32000, message: 'Rate limit exceeded' },
+ },
+ }));
+
if (this.config.requestTimeout) {
this.app.use((req, res, next) => {
res.setTimeout(this.config.requestTimeout!, () => {
diff --git a/v3/pnpm-lock.yaml b/v3/pnpm-lock.yaml
index 368a0303c6..80cb892a8f 100644
--- a/v3/pnpm-lock.yaml
+++ b/v3/pnpm-lock.yaml
@@ -165,6 +165,9 @@ importers:
express:
specifier: '>=4.22.2'
version: 5.2.1
+ express-rate-limit:
+ specifier: '>=8.4.1'
+ version: 8.6.2([email protected])
fast-uri:
specifier: 3.1.5
version: 3.1.5
@@ -408,6 +411,9 @@ importers:
express:
specifier: '>=4.22.2'
version: 5.2.1
+ express-rate-limit:
+ specifier: ^8.4.1
+ version: 8.6.2([email protected])
helmet:
specifier: ^7.1.0
version: 7.2.0
@@ -1856,7 +1862,7 @@ packages:
eventsource: 3.0.7
eventsource-parser: 3.0.6
express: 5.2.1
- express-rate-limit: 8.3.2([email protected])
+ express-rate-limit: 8.6.2([email protected])
hono: 4.12.11
jose: 6.1.3
json-schema-typed: 8.0.2
@@ -1886,7 +1892,7 @@ packages:
eventsource: 3.0.7
eventsource-parser: 3.0.6
express: 5.2.1
- express-rate-limit: 8.3.2([email protected])
+ express-rate-limit: 8.6.2([email protected])
hono: 4.12.11
jose: 6.1.3
json-schema-typed: 8.0.2
@@ -7047,7 +7053,7 @@ packages:
argon2: 0.44.0
bcrypt: 6.0.0
better-sqlite3: 12.9.0
- express-rate-limit: 8.3.2([email protected])
+ express-rate-limit: 8.6.2([email protected])
helmet: 8.1.0
hnswlib-node: 3.0.0
sharp: 0.32.6
@@ -7108,7 +7114,7 @@ packages:
argon2: 0.44.0
bcrypt: 6.0.0
better-sqlite3: 12.9.0
- express-rate-limit: 8.3.2([email protected])
+ express-rate-limit: 8.6.2([email protected])
helmet: 8.1.0
hnswlib-node: 3.0.0
sharp: 0.32.6
@@ -8891,15 +8897,17 @@ packages:
express: 5.2.1
dev: false
- resolution: {integrity: sha512-77VmFeJkO0/rvimEDuUC5H30oqUC4EyOhyGccfqoLebB0oiEYfM7nwPrsDsBL1gsTpwfzX8SFy2MT3TDyRq+bg==}
+ resolution: {integrity: sha512-YH4ru+eOJxQABscKFfRCy9R7x9QFGdezclVMwwgFFndzS2Xnm0uo6B0ABZsLhcpeptGv2qvuJVWlQr9gQZoC3A==}
engines: {node: '>= 16'}
- requiresBuild: true
peerDependencies:
express: '>=4.22.2'
dependencies:
+ debug: 4.4.3
express: 5.2.1
- ip-address: 10.1.0
+ ip-address: 10.5.0
+ transitivePeerDependencies:
+ - supports-color
resolution: {integrity: sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==}
@@ -9826,6 +9834,12 @@ packages:
resolution: {integrity: sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==}
engines: {node: '>= 12'}
requiresBuild: true
+ dev: false
+ optional: true
+
+ resolution: {integrity: sha512-R5SnVLJmgYYvf2F2ZgwSBnelz5G4q5AxIC277GDfUaNbrZKNANcBC7RHqYYePlszf4kBolVkJauG0ZjHHFh55g==}
+ engines: {node: '>= 12'}
resolution: {integrity: sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==}