Skip to content

armgit / AiSOC

Public Imported from GitHub
0

Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.

fix: add rate limiting to /internal/push endpoint (js/missing-rate-limiting #168)

Beenu Arora7901fa7b79ce
diff --git a/services/realtime/src/index.ts b/services/realtime/src/index.ts
index 94f1bd301..49a49b2da 100644
--- a/services/realtime/src/index.ts
+++ b/services/realtime/src/index.ts
@@ -157,11 +157,14 @@ const SSE_RATE_LIMIT = 20;
const SSE_RATE_WINDOW_MS = 60_000;
const sseRateLimitExceeded = makeRateLimiter(SSE_RATE_LIMIT, SSE_RATE_WINDOW_MS);
-// Rate limiter for the internal agent-event endpoint: max 200 req/s per IP.
+// Rate limiter for the internal agent-event endpoint: max 200 req/min per IP.
// This endpoint is internal-only (token-gated) but we still rate-limit to
// protect against misconfigured or runaway callers.
const internalEventRateLimitExceeded = makeRateLimiter(200, 60_000);
+// Rate limiter for the internal push endpoint: max 200 req/min per IP.
+const internalPushRateLimitExceeded = makeRateLimiter(200, 60_000);
+
// --- SSE endpoint ---
app.get('/sse', (req, res) => {
const ip = (req.headers['x-forwarded-for'] as string | undefined)?.split(',')[0]?.trim()
@@ -294,6 +297,15 @@ function requireInternal(req: express.Request, res: express.Response): boolean {
// `internal/agent-event`.
app.post('/internal/push', async (req, res) => {
if (!requireInternal(req, res)) return;
+
+ const ip = (req.headers['x-forwarded-for'] as string | undefined)?.split(',')[0]?.trim()
+ || req.socket.remoteAddress
+ || 'unknown';
+ if (internalPushRateLimitExceeded(ip)) {
+ res.status(429).json({ error: 'Rate limit exceeded' });
+ return;
+ }
+
await pushManager.internalNotifyHandler(req, res);
});