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.
Python agentic-aiai-securityalert-triageblue-teamcybersecuritydetection-engineeringincident-responselanggraphllm-agentsmcpmitre-attackmodel-context-protocolpurple-teamsecurity-operationsself-hostedsiemsoarsocthreat-detectionthreat-intelligence
security: resolve remaining CodeQL alerts (round 3)
Beenu Arora3516d880bd16
diff --git a/services/api/app/api/v1/endpoints/connectors.py b/services/api/app/api/v1/endpoints/connectors.pyindex 8b44b01fe..9aef78a9b 100644--- a/services/api/app/api/v1/endpoints/connectors.py+++ b/services/api/app/api/v1/endpoints/connectors.py@@ -233,9 +233,9 @@ async def _proxy_test_connection(resp = await client.post(url, json=payload)except httpx.HTTPError as exc:logger.warning(- "connectors_service.test.unreachable url=%s err=%s",- _safe_log_val(url),- str(exc).replace("\n", " ").replace("\r", " "),+ "connectors_service.test.unreachable connector_type=%s err=%s",+ connector_type,+ type(exc).__name__,)raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE,diff --git a/services/api/app/api/v1/endpoints/nl_query.py b/services/api/app/api/v1/endpoints/nl_query.pyindex f3f07697c..2729f0192 100644--- a/services/api/app/api/v1/endpoints/nl_query.py+++ b/services/api/app/api/v1/endpoints/nl_query.py@@ -277,10 +277,10 @@ async def execute_query(body.question, body.index_pattern, body.time_range_hours)- es_url = (- body.es_url- or getattr(settings, "ES_URL", None)- or getattr(settings, "ELASTICSEARCH_URL", None)+ # Always read the ES URL from server-side settings — never from user-supplied+ # body fields — to prevent partial-SSRF attacks (CodeQL py/partial-ssrf).+ es_url = getattr(settings, "ES_URL", None) or getattr(+ settings, "ELASTICSEARCH_URL", None)es_api_key = body.es_api_key or getattr(settings, "ES_API_KEY", None)diff --git a/services/realtime/src/index.ts b/services/realtime/src/index.tsindex 724f9de3f..f31a9b0c1 100644--- a/services/realtime/src/index.ts+++ b/services/realtime/src/index.ts@@ -5,6 +5,7 @@ import { WebSocketServer } from 'ws';import { Kafka } from 'kafkajs';import Redis from 'ioredis';import pino from 'pino';+import rateLimit from 'express-rate-limit';import { PushManager } from './push';@@ -152,74 +153,30 @@ function makeRateLimiter(limit: number, windowMs: number) {};}-// Simple IP-based rate limiter for SSE: max 20 connections per IP per minute.-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/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);--// Express middleware wrappers so CodeQL recognises these as rate-limiting guards-// (the inline-check pattern is not detected by CodeQL's js/missing-rate-limiting query).-function sseRateLimit(- req: express.Request,- res: express.Response,- next: express.NextFunction,-): void {- const ip =- (req.headers['x-forwarded-for'] as string | undefined)- ?.split(',')[0]- ?.trim() ||- req.socket.remoteAddress ||- 'unknown';- if (sseRateLimitExceeded(ip)) {- res.status(429).json({ error: 'Rate limit exceeded' });- return;- }- next();-}+// Rate limiters using express-rate-limit (recognised by CodeQL js/missing-rate-limiting).+const sseRateLimit = rateLimit({+ windowMs: 60_000,+ max: 20,+ standardHeaders: true,+ legacyHeaders: false,+ message: { error: 'Rate limit exceeded' },+});-function internalEventRateLimit(- req: express.Request,- res: express.Response,- next: express.NextFunction,-): void {- const ip =- (req.headers['x-forwarded-for'] as string | undefined)- ?.split(',')[0]- ?.trim() ||- req.socket.remoteAddress ||- 'unknown';- if (internalEventRateLimitExceeded(ip)) {- res.status(429).json({ error: 'Rate limit exceeded' });- return;- }- next();-}+const internalEventRateLimit = rateLimit({+ windowMs: 60_000,+ max: 200,+ standardHeaders: true,+ legacyHeaders: false,+ message: { error: 'Rate limit exceeded' },+});-function internalPushRateLimit(- req: express.Request,- res: express.Response,- next: express.NextFunction,-): void {- 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;- }- next();-}+const internalPushRateLimit = rateLimit({+ windowMs: 60_000,+ max: 200,+ standardHeaders: true,+ legacyHeaders: false,+ message: { error: 'Rate limit exceeded' },+});// --- SSE endpoint ---app.get('/sse', sseRateLimit, (req, res) => {@@ -321,25 +278,13 @@ async function startKafkaConsumer() {// Public key is needed by the browser to subscribe; the rest are// authenticated routes the API gateway forwards on behalf of a user.// Rate-limit push mutation routes: 20 req / min per IP to prevent abuse.-const pushSubscribeRateLimitExceeded = makeRateLimiter(20, 60_000);--function pushRateLimit(- req: express.Request,- res: express.Response,- next: express.NextFunction,-): void {- const ip =- (req.headers['x-forwarded-for'] as string | undefined)- ?.split(',')[0]- ?.trim() ||- req.socket.remoteAddress ||- 'unknown';- if (pushSubscribeRateLimitExceeded(ip)) {- res.status(429).json({ error: 'Rate limit exceeded' });- return;- }- next();-}+const pushRateLimit = rateLimit({+ windowMs: 60_000,+ max: 20,+ standardHeaders: true,+ legacyHeaders: false,+ message: { error: 'Rate limit exceeded' },+});app.get('/v1/push/public-key', pushManager.publicKeyHandler);app.post('/v1/push/subscribe', pushRateLimit, pushManager.subscribeHandler);