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.

fix(hunt-reports): a parameter rather than a clause spliced into the list query

Beenu Arorab7ab240f06e4
diff --git a/services/api/app/api/v1/endpoints/hunt_reports.py b/services/api/app/api/v1/endpoints/hunt_reports.py
index 53f993dcd..eb0b1dc71 100644
--- a/services/api/app/api/v1/endpoints/hunt_reports.py
+++ b/services/api/app/api/v1/endpoints/hunt_reports.py
@@ -160,15 +160,28 @@ async def list_reports(
case_id: uuid.UUID | None = Query(default=None),
limit: int = Query(default=50, ge=1, le=200),
) -> list[HuntReportOut]:
- stmt = (
- "SELECT * FROM aisoc_hunt_reports WHERE tenant_id = :tenant_id "
- + ("AND case_id = :case_id " if case_id else "")
- + "ORDER BY created_at DESC LIMIT :limit"
+ # A parameter, not a clause spliced into the statement. Both forms were
+ # correct -- the only variable was one of two literals in this module --
+ # and only this one stops reading as dynamic SQL to every scanner and
+ # every reviewer that looks at it.
+ rows = (
+ (
+ await db.execute(
+ text(
+ "SELECT * FROM aisoc_hunt_reports "
+ "WHERE tenant_id = :tenant_id "
+ " AND (CAST(:case_id AS uuid) IS NULL OR case_id = CAST(:case_id AS uuid)) "
+ "ORDER BY created_at DESC LIMIT :limit"
+ ).bindparams(
+ tenant_id=current_user.tenant_id,
+ case_id=str(case_id) if case_id else None,
+ limit=limit,
+ )
+ )
+ )
+ .mappings()
+ .all()
)
- params: dict[str, Any] = {"tenant_id": current_user.tenant_id, "limit": limit}
- if case_id:
- params["case_id"] = case_id
- rows = (await db.execute(text(stmt).bindparams(**params))).mappings().all() # noqa: S608 - the only variable is a literal clause above
return [_out(dict(row)) for row in rows]