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(gate): a set-returning function in FROM is not a table
Beenu Arora6446542c86b3
diff --git a/scripts/check_raw_sql_columns.py b/scripts/check_raw_sql_columns.pyindex 8b23f342e..0ef0059a7 100644--- a/scripts/check_raw_sql_columns.py+++ b/scripts/check_raw_sql_columns.py@@ -377,8 +377,17 @@ _INSERT = re.compile(r"\bINSERT\s+(?:OR\s+\w+\s+)?INTO\s+([^\s(;]+)", re.I)#: resolution and alias tracking, and a pattern that silently mis-resolves#: is worse than one that declines to try — those are reported as#: unresolvable rather than passed.+# The trailing `(?!\s*\()` is the difference between a table and a+# set-returning function. `FROM jsonb_array_elements(col) AS k` is ordinary+# Postgres and names no table at all, but the name matches the same character+# class a table does, so without this the gate reported "no migration creates+# 'jsonb_array_elements'" about a statement that runs perfectly well — a+# false positive in the one bucket that is supposed to mean "this cannot+# succeed on any deployment". A table is never followed by an open paren;+# a subquery (`FROM (SELECT ...)`) starts with one and never matches the+# class in the first place._SELECT = re.compile(- r"\bSELECT\s+(?!.*\bJOIN\b)(.+?)\s+FROM\s+(?:ONLY\s+)?([a-z_][a-z0-9_]*)\b",+ r"\bSELECT\s+(?!.*\bJOIN\b)(.+?)\s+FROM\s+(?:ONLY\s+)?([a-z_][a-z0-9_]*)\b(?!\s*\()",re.I | re.S,)@@ -994,6 +1003,22 @@ def _detects_injected_drift() -> list[tuple[str, bool]]:"declines a SELECT whose projection it could not fully read",kinds("SQL = 'SELECT COUNT(*) AS n FROM widgets'\n") == set(),),+ (+ # A `FROM` item is not always a table. Postgres lets a+ # set-returning function stand where one does, and the name+ # matches the same character class, so the gate reported+ # "no migration creates 'jsonb_array_elements'" about a+ # statement that runs -- a false positive in the one bucket+ # whose message says the statement cannot succeed anywhere.+ "does not mistake a set-returning function in FROM for a table",+ kinds('SQL = "SELECT k FROM jsonb_array_elements(a || b) AS k"\n') == set(),+ ),+ (+ # And the other direction, so the lookahead above cannot be+ # widened into "ignore anything after FROM".+ "still fails a real table that no migration creates",+ kinds("SQL = 'SELECT id, name FROM jsonb_array_elements_but_a_table'\n") == {"unknown-table"},+ ),]