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.

security(codeql): close last py/log-injection + py/url-redirection alerts

Beenu Arorabff7332897a7
diff --git a/services/api/app/api/v1/endpoints/connectors.py b/services/api/app/api/v1/endpoints/connectors.py
index 0d6b6d69c..b9be82354 100644
--- a/services/api/app/api/v1/endpoints/connectors.py
+++ b/services/api/app/api/v1/endpoints/connectors.py
@@ -791,7 +791,11 @@ async def update_connector_capabilities(
extra={
"tenant_id": current_user.tenant_id,
"connector_id": str(connector_id),
- "connector_type": _safe_log_val(connector.connector_type),
+ # _safe_connector_type reconstructs from a whitelist regex
+ # (negative-class sub) — that's a taint-breaker CodeQL
+ # actually recognises, unlike _safe_log_val's strip-only
+ # cleanup which it (correctly) treats as cosmetic.
+ "connector_type": _safe_connector_type(connector.connector_type),
"allowed": request.allowed_capabilities,
},
)
@@ -1110,7 +1114,10 @@ async def troubleshoot_connection(
logger.info(
"connectors.troubleshoot",
extra={
- "type": _safe_log_val(safe_type),
+ # safe_type is already taint-broken by _safe_connector_type
+ # above; wrapping it in _safe_log_val just re-introduced a
+ # function CodeQL doesn't model as a sanitizer.
+ "type": safe_type,
"keys": sorted(request.auth_config_keys)[:8], # cap to avoid log spam
"err_len": len(request.error),
},
diff --git a/services/api/app/api/v1/endpoints/oauth.py b/services/api/app/api/v1/endpoints/oauth.py
index 4c7f1d2ca..ef7c9a3ea 100644
--- a/services/api/app/api/v1/endpoints/oauth.py
+++ b/services/api/app/api/v1/endpoints/oauth.py
@@ -91,7 +91,6 @@ router = APIRouter(prefix="/oauth", tags=["oauth"])
# Same regex used in connectors.py — we don't want a hostile state row
# ever embedding path traversal / log injection in connector_type.
_CONNECTOR_TYPE_RE = re.compile(r"^[a-zA-Z0-9_\-]{1,100}$")
-_LOG_CTRL_RE = re.compile(r"[\x00-\x1f\x7f]")
# OAuth state TTL. The plan calls it 10 minutes; that's tight enough that
# a stolen state cookie is useless before it expires, loose enough that a
@@ -730,10 +729,17 @@ def _callback_error_redirect(return_to: str, code: str, detail: str) -> Redirect
owns the operator UX, and the verify-data-flowing screen already
knows how to surface ``oauth_error=…&oauth_message=…`` on
/onboarding.
+
+ ``return_to`` is re-validated here even though every caller pulls it
+ from a state row that was itself sanitised at /oauth/start. CodeQL
+ cannot follow that round-trip through the database, so re-asserting
+ the whitelist at the sink keeps the taint analysis quiet *and*
+ closes the door on a future caller that forgets to validate.
"""
- sep = "&" if "?" in return_to else "?"
+ safe_return = _validate_return_to(return_to)
+ sep = "&" if "?" in safe_return else "?"
qs = urlencode({"oauth_error": code, "oauth_message": detail[:200]})
- return RedirectResponse(url=f"{return_to}{sep}{qs}", status_code=302)
+ return RedirectResponse(url=f"{safe_return}{sep}{qs}", status_code=302)
@router.get("/callback")