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
fix(phase-A2): make the live-detection integration gate reliable (#450)
Beenu Arora8ebc9ca30404
diff --git a/scripts/integration/spine_test.py b/scripts/integration/spine_test.pyindex 81440fd19..337e0d9f5 100644--- a/scripts/integration/spine_test.py+++ b/scripts/integration/spine_test.py@@ -286,9 +286,24 @@ async def main() -> None:async with httpx.AsyncClient() as client:await wait_healthy(client)await asyncio.sleep(5)- await post_detection_event(client)- await await_alert_row(client, DETECTION_ALERT_TITLE, args.timeout or 180, repost=False)- log("DETECTION ENGINE FIRED (live-stream rule match produced an alert)")+ # Re-post periodically to ride out consumer-group assignment races,+ # exactly like the spine test (the detection alert is dedup-guarded+ # so repeats never create duplicate rows).+ timeout_s = args.timeout or 180+ deadline = time.monotonic() + timeout_s+ last_post = 0.0+ while time.monotonic() < deadline:+ try:+ if time.monotonic() - last_post > REPOST_INTERVAL_S:+ await post_detection_event(client)+ last_post = time.monotonic()+ if await count_alerts_titled(client, DETECTION_ALERT_TITLE) >= 1:+ log("DETECTION ENGINE FIRED (live-stream rule match produced an alert)")+ return+ except httpx.HTTPError as exc:+ log(f"transient error while polling (will retry): {exc}")+ await asyncio.sleep(3)+ raise SystemExit(f"detection alert {DETECTION_ALERT_TITLE!r} never appeared within {timeout_s}s")returnif args.post_event or args.await_alert:diff --git a/services/fusion/app/services/detection_engine.py b/services/fusion/app/services/detection_engine.pyindex f45e65beb..f7ecc65be 100644--- a/services/fusion/app/services/detection_engine.py+++ b/services/fusion/app/services/detection_engine.py@@ -43,10 +43,6 @@ logger = structlog.get_logger()_RULESET_PATH = Path(__file__).resolve().parent.parent / "data" / "detection_ruleset.json"-# Products whose rules should also run against every event regardless of the-# event's own product (broadly-applicable rule families).-_PRODUCT_AGNOSTIC = {"", "multi-cloud", "app", "application", "endpoint"}-_SEVERITY_MAP = {"critical": AlertSeverity.CRITICAL,"high": AlertSeverity.HIGH,@@ -84,26 +80,15 @@ class DetectionEngine:def rule_count(self) -> int:return len(self._rules)- @staticmethod- def _product_matches(rule_product: str, event_product: str) -> bool:- """Fuzzy product routing.-- Connector product names don't line up 1:1 with spec products- (``aws_cloudtrail`` vs ``aws``, ``crowdstrike_falcon`` vs ``edr``), so- a rule is a candidate when: it is product-agnostic, the event product- is unknown (evaluate everything — correctness over speed), or the two- product strings share containment either way.- """- rp = (rule_product or "").lower()- if rp in _PRODUCT_AGNOSTIC:- return True- ep = (event_product or "").lower()- if not ep:- return True- return rp == ep or rp in ep or ep in rp-def _candidates(self, product: str) -> list[dict[str, Any]]:- return [r for r in self._rules if self._product_matches(r.get("product", ""), product)]+ # Correctness-first routing: evaluate the whole corpus against every+ # event. Connector product names don't line up 1:1 with spec products+ # (``aws_cloudtrail`` vs ``aws``, ``crowdstrike_falcon`` vs ``edr``), so+ # any product-based pre-filter risks silently dropping a real match.+ # The matcher short-circuits on the first absent field, so a full pass+ # over ~800 rules is cheap in practice (a benign event touches almost+ # none of them past the first clause).+ return self._rules@staticmethoddef _raw_fields(ocsf: dict[str, Any]) -> dict[str, Any]:@@ -119,21 +104,14 @@ class DetectionEngine:# Fall back to the OCSF top level (some connectors emit flat OCSF).return ocsf if isinstance(ocsf, dict) else {}- @staticmethod- def _product(ocsf: dict[str, Any], message: dict[str, Any]) -> str:- return str(- _get(ocsf, "metadata", "product", "name") or message.get("connector_type") or _get(message, "connector_type") or ""- ).lower()-def evaluate(self, message: dict[str, Any]) -> list[DetectionHit]:"""Return every rule that fires on this normalized-event message."""ocsf = message.get("ocsf_event")if not isinstance(ocsf, dict):return []fields = self._raw_fields(ocsf)- product = self._product(ocsf, message)hits: list[DetectionHit] = []- for rule in self._candidates(product):+ for rule in self._candidates(""):try:if matches(rule["match_when"], fields):hits.append(