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
chore(security): resolve remaining round-2 CodeQL alerts (#157)
Beenu Aroraec6dd1bcf1c3
diff --git a/services/agents/app/context/bundle.py b/services/agents/app/context/bundle.pyindex d310a95e9..cbd9daed3 100644--- a/services/agents/app/context/bundle.py+++ b/services/agents/app/context/bundle.py@@ -237,10 +237,12 @@ class ThreatIntelMatch(BaseModel):# Allowed top-level keys in ``summary_for_llm`` — kept here (not in# ``app/llm/contract.py``) so the model is the source of truth and the-# contract validator can import this whitelist.-# Imported by tests (e.g. ``test_context_bundle.py``) and by contract-# validators; CodeQL flags it as module-local-unused, suppress that.-_LLM_SAFE_KEYS = ( # lgtm[py/unused-global-variable]+# contract validator can import this whitelist. Public (no leading+# underscore) because it is imported by tests and by external contract+# validators; the previous private-with-suppression form tripped CodeQL+# ``py/unused-global-variable`` because the inline suppression marker+# was not honoured by the analyzer.+LLM_SAFE_KEYS = ("incident_id","alert_summary","entity_count",@@ -355,7 +357,7 @@ class ContextBundle(BaseModel):def summary_for_llm(self) -> dict[str, Any]:"""Pre-digested, contract-safe summary for LLM prompts.- Every key returned here is on ``_LLM_SAFE_KEYS`` and contains either+ Every key returned here is on ``LLM_SAFE_KEYS`` and contains eithera scalar, a small list of scalars, or a list of short string summaries— never raw OCSF / log payloads. ``LLMInputContract`` (T2.3) treatsthe output of this method as the canonical safe shape.diff --git a/services/agents/tests/test_context_bundle.py b/services/agents/tests/test_context_bundle.pyindex 05d5b35fd..566e1ee80 100644--- a/services/agents/tests/test_context_bundle.py+++ b/services/agents/tests/test_context_bundle.py@@ -44,7 +44,7 @@ from app.context import ( # noqa: E402EntityRef,extract_entities,)-from app.context.bundle import _LLM_SAFE_KEYS # noqa: E402+from app.context.bundle import LLM_SAFE_KEYS # noqa: E402from app.models.state import InvestigationState # noqa: E402_DATASET_PATH = _TESTS_DIR / "eval_data" / "synthetic_incidents.json"@@ -202,7 +202,7 @@ class ContextBundleSummaryTests(unittest.TestCase):)summary = bundle.summary_for_llm()for key in summary:- self.assertIn(key, _LLM_SAFE_KEYS, f"unexpected key in summary_for_llm: {key}")+ self.assertIn(key, LLM_SAFE_KEYS, f"unexpected key in summary_for_llm: {key}")def test_prompt_context_lines_empty_when_bundle_empty(self) -> None:bundle = ContextBundle(incident_id=uuid4())diff --git a/services/api/app/api/v1/endpoints/waitlist.py b/services/api/app/api/v1/endpoints/waitlist.pyindex 895cd0a5b..b75612884 100644--- a/services/api/app/api/v1/endpoints/waitlist.py+++ b/services/api/app/api/v1/endpoints/waitlist.py@@ -61,6 +61,7 @@ from app.db.database import get_dbfrom app.models.waitlist import (ALLOWED_WAITLIST_STATUSES,WAITLIST_STATUS_CONTACTED,+ WAITLIST_STATUS_DECLINED,WAITLIST_STATUS_NEW,WAITLIST_STATUS_ONBOARDED,WaitlistEntry,@@ -88,6 +89,23 @@ _MAX_MOTIVATION_LEN: int = 4000_MAX_SOC_STACK_ENTRIES: int = 20_MAX_LIST_LIMIT: int = 500++# Maps a user-supplied / DB-stored status value to the *hardcoded literal*+# that is safe to put into a log record. Looking up the value (rather than+# echoing the raw status through ``status if status in ALLOWED... else+# "<invalid>"``) breaks CodeQL's taint flow because the value side of the+# mapping is never derived from the input — it is a compile-time string+# literal. This satisfies ``py/log-injection`` without losing the+# operational signal. The keys mirror ``ALLOWED_WAITLIST_STATUSES``; any+# value outside that allowlist falls back to ``"<invalid>"`` at the call+# site.+_STATUS_LOG_TOKENS: dict[str, str] = {+ WAITLIST_STATUS_NEW: "new",+ WAITLIST_STATUS_CONTACTED: "contacted",+ WAITLIST_STATUS_ONBOARDED: "onboarded",+ WAITLIST_STATUS_DECLINED: "declined",+}+# RFC 5322 is famously permissive; we use a forgiving "[email protected]"# regex that catches obvious typos without rejecting legitimate edge# cases (plus-addressing, hyphenated subdomains, etc.).@@ -432,18 +450,17 @@ async def patch_entry(# Both ``previous`` (DB enum) and ``payload.status`` (Pydantic-validated# against ``ALLOWED_WAITLIST_STATUSES``) are constrained to a known- # allowlist before we ever reach this point. Re-resolve them through- # the allowlist so the values we put into the log record cannot- # possibly carry log-injection-friendly payloads (newlines, ANSI- # escapes, log-spoofed key=value pairs) even if upstream validation- # is ever weakened. Anything outside the allowlist becomes the literal- # string ``"<invalid>"`` instead of being echoed verbatim. This- # silences CodeQL ``py/log-injection`` cleanly without losing the- # operational signal.- safe_previous = previous if previous in ALLOWED_WAITLIST_STATUSES else "<invalid>"- safe_next = (- payload.status if payload.status in ALLOWED_WAITLIST_STATUSES else "<invalid>"- )+ # allowlist before we ever reach this point. We still look the values+ # up via ``_STATUS_LOG_TOKENS`` so what lands in the log record is a+ # hardcoded string literal (never the raw input). Any value outside+ # the allowlist becomes ``"<invalid>"``. This breaks CodeQL's taint+ # flow for ``py/log-injection``: the conditional ``x if x in+ # ALLOWED... else "<invalid>"`` form was not enough because CodeQL+ # still saw the True branch as carrying the original tainted value+ # through to the logger. The dict-lookup form returns a value that+ # is provably independent of the input string.+ safe_previous = _STATUS_LOG_TOKENS.get(previous, "<invalid>")+ safe_next = _STATUS_LOG_TOKENS.get(payload.status, "<invalid>")logger.info("waitlist_status_transition",extra={diff --git a/services/api/app/services/effective_permissions/service.py b/services/api/app/services/effective_permissions/service.pyindex c48ad73c7..422e587cb 100644--- a/services/api/app/services/effective_permissions/service.py+++ b/services/api/app/services/effective_permissions/service.py@@ -50,6 +50,21 @@ SUPPORTED_PROVIDERS: dict[str, type[Resolver]] = {}+# Maps a user-supplied provider name to the *hardcoded literal* that is safe+# to log. Looking up the value (rather than passing the raw ``provider``+# argument through a conditional ``if ... else "<unsupported>"`` expression)+# breaks CodeQL's taint flow because the value side of the mapping is never+# derived from the input — it is a compile-time string literal. This satisfies+# ``py/log-injection`` without losing the operational signal.+_PROVIDER_LOG_TOKENS: dict[str, str] = {+ "aws": "aws",+ "azure": "azure",+ "gcp": "gcp",+ "okta": "okta",+ "gws": "gws",+}++SnapshotLoader = Callable[[str], dict[str, Any]]@@ -67,11 +82,14 @@ def _default_snapshot_loader(provider: str) -> dict[str, Any]:# / query parameters). Even though the calling resolver only dispatches# on values in ``SUPPORTED_PROVIDERS``, the loader stub is reachable# before that dispatch, so we constrain what we put into the log- # record. Anything outside the known allowlist is logged as the- # literal ``"<unsupported>"`` so an attacker cannot smuggle control- # characters or fake log lines through this code path. Resolves- # CodeQL ``py/log-injection`` without losing the operational signal.- safe_provider = provider if provider in SUPPORTED_PROVIDERS else "<unsupported>"+ # record. We look up a hardcoded literal from ``_PROVIDER_LOG_TOKENS``+ # so the value that lands in the log line is provably independent of+ # the input string — anything outside the known allowlist is logged as+ # the literal ``"<unsupported>"``. This stops an attacker from smuggling+ # control characters or fake log lines through this code path and+ # resolves CodeQL ``py/log-injection`` without losing the operational+ # signal.+ safe_provider = _PROVIDER_LOG_TOKENS.get(provider, "<unsupported>")logger.warning("no production snapshot loader wired for provider=%s — returning {}",safe_provider,diff --git a/services/api/tests/test_business_context.py b/services/api/tests/test_business_context.pyindex 6fd4039c6..70b7c3a37 100644--- a/services/api/tests/test_business_context.py+++ b/services/api/tests/test_business_context.py@@ -75,7 +75,6 @@ from app.services.business_context.models import (ALLOWED_OPS,ALLOWED_ROUTES,ALLOWED_SEVERITIES,- BusinessContextRule,RuleAction,RuleCondition,)