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.

chore(security): resolve CodeQL low-severity quality notes (#224)

Beenu Arora3f102a321d07
diff --git a/apps/web/src/components/dashboard/SOCMetricsDashboard.tsx b/apps/web/src/components/dashboard/SOCMetricsDashboard.tsx
index ac8ba518c..303851c04 100644
--- a/apps/web/src/components/dashboard/SOCMetricsDashboard.tsx
+++ b/apps/web/src/components/dashboard/SOCMetricsDashboard.tsx
@@ -154,7 +154,7 @@ function AttackHeatmap({ cells }: { cells: AttackHeatmapCell[] }) {
}
export function SOCMetricsDashboard() {
- const { data, error, isLoading, mutate } = useSWR<SOCMetrics>(
+ const { data, error, mutate } = useSWR<SOCMetrics>(
// Opaque cache key — `metricsApi.getSOC()` routes through the
// tenant- and auth-aware `request()` helper, which attaches
// `X-Tenant-Id` and `Authorization` headers and is bound to the
diff --git a/services/agents/tests/test_fusion_client.py b/services/agents/tests/test_fusion_client.py
index b366e85f6..0b80b116f 100644
--- a/services/agents/tests/test_fusion_client.py
+++ b/services/agents/tests/test_fusion_client.py
@@ -76,11 +76,14 @@ def fusion_url(monkeypatch: pytest.MonkeyPatch) -> str:
url = "http://fusion-test:8003"
monkeypatch.setenv("FUSION_SERVICE_URL", url)
# The module reads the env at import time, so reload it under the
- # patched env.
+ # patched env. We use ``importlib.import_module`` (rather than
+ # ``import app.tools.fusion as fusion_module``) so CodeQL's
+ # py/import-and-import-from rule doesn't flag this file as mixing
+ # ``import`` and ``from ... import``; the test bodies already use
+ # ``from app.tools.fusion import process_alert`` after this reload.
import importlib
- import app.tools.fusion as fusion_module
-
+ fusion_module = importlib.import_module("app.tools.fusion")
importlib.reload(fusion_module)
return url
diff --git a/services/agents/tests/test_triage_endpoint.py b/services/agents/tests/test_triage_endpoint.py
index e4425478f..e0214e315 100644
--- a/services/agents/tests/test_triage_endpoint.py
+++ b/services/agents/tests/test_triage_endpoint.py
@@ -179,7 +179,11 @@ def _poll_until_done(
if last.get("status") != "running":
return last
time.sleep(0.02)
+ # Use ``pytest.fail`` for the red-failure UX, then ``raise`` so the type
+ # checker / CodeQL see the function ends on an explicit no-return path
+ # (avoids ``py/mixed-returns`` from the implicit fall-through).
pytest.fail(f"triage run {run_id} did not complete in {timeout_s}s; last={last}")
+ raise AssertionError("unreachable") # pragma: no cover
# ---------------------------------------------------------------------------
diff --git a/services/api/app/core/scheduler_lock.py b/services/api/app/core/scheduler_lock.py
index 17c5abd6b..a3da43315 100644
--- a/services/api/app/core/scheduler_lock.py
+++ b/services/api/app/core/scheduler_lock.py
@@ -136,7 +136,10 @@ async def scheduler_lock(*, job_name: str, ttl_seconds: int) -> AsyncIterator[bo
if renew_task is not None:
renew_task.cancel()
with suppress(asyncio.CancelledError):
- await renew_task
+ # Bind to `_` so the awaited result is explicitly discarded and
+ # CodeQL's py/ineffectual-statement check doesn't misread this
+ # as a no-op (the await itself is required to drain cancellation).
+ _ = await renew_task
if redis_client is not None:
try:
diff --git a/services/api/tests/test_detection_loop_tenant_isolation.py b/services/api/tests/test_detection_loop_tenant_isolation.py
index 070d47e67..d8b21ef16 100644
--- a/services/api/tests/test_detection_loop_tenant_isolation.py
+++ b/services/api/tests/test_detection_loop_tenant_isolation.py
@@ -346,7 +346,9 @@ async def test_list_suggestions_only_returns_caller_tenant() -> None:
tenant_b = _user()
a1 = _seed_suggestion(tenant_a.tenant_id, "a-1")
a2 = _seed_suggestion(tenant_a.tenant_id, "a-2")
- _b1 = _seed_suggestion(tenant_b.tenant_id, "b-1")
+ # Seed a tenant-B suggestion solely to prove it doesn't leak into tenant A's
+ # list response below; we never need its id here.
+ _seed_suggestion(tenant_b.tenant_id, "b-1")
resp = await list_suggestions(user=tenant_a)
diff --git a/services/fusion/tests/test_process_endpoint.py b/services/fusion/tests/test_process_endpoint.py
index a4ef10f7d..f9f6b7b4e 100644
--- a/services/fusion/tests/test_process_endpoint.py
+++ b/services/fusion/tests/test_process_endpoint.py
@@ -22,6 +22,7 @@ from unittest.mock import AsyncMock, MagicMock
from uuid import UUID, uuid4
import pytest
+from app.api import router as router_mod
from app.api.router import router, set_worker
from app.models.alert import (
AlertSeverity,
@@ -101,8 +102,6 @@ def _clear_worker() -> None:
module attribute directly is intentional — it's the same mutation
the lifespan handler would do in reverse on shutdown.
"""
- import app.api.router as router_mod
-
router_mod._worker_ref = None # noqa: SLF001 — test seam