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(connectors): exclude scheduler-owned keys on saved-connector test-connection (#1555)

alexmateescu00ea72e9439d
diff --git a/services/connectors/app/api/router.py b/services/connectors/app/api/router.py
index 312763d14..bd1069948 100644
--- a/services/connectors/app/api/router.py
+++ b/services/connectors/app/api/router.py
@@ -330,7 +330,18 @@ async def test_connector_connection(connector_id: str, payload: TestConnectionRe
# validates both blobs against the schema before we ever see them, so
# this ordering is defensive belt-and-braces rather than a real
# boundary.
- kwargs = {**payload.auth_config, **payload.connector_config}
+ #
+ # Exception: the scheduler-owned runtime state keys must not reach the
+ # constructor. ``record_checkpoint`` persists the ingest cursor into
+ # ``connector_config.checkpoint``, and the scheduler strips it (plus the
+ # other scheduler-only keys) before construction — while this route
+ # merged the blob verbatim, so once any poll had recorded a checkpoint,
+ # EVERY saved-connector test raised TypeError -> 422 ("unexpected
+ # keyword argument 'checkpoint'") on every connector whose __init__
+ # does not take it. One exclusion set, owned by ``_connector_kwargs``
+ # above: a second hand-written list here is how ``filter_rules`` would
+ # have been missed, and how the next scheduler-only key drifts.
+ kwargs = {**payload.auth_config, **_connector_kwargs(payload.connector_config)}
# Before the constructor, and before any socket could open: a tenant-set
# base_url pointing at cloud metadata, loopback or an internal service is
diff --git a/services/connectors/tests/test_egress_guard.py b/services/connectors/tests/test_egress_guard.py
index 53ddf6f12..e4e2ae1fa 100644
--- a/services/connectors/tests/test_egress_guard.py
+++ b/services/connectors/tests/test_egress_guard.py
@@ -179,3 +179,39 @@ async def test_the_test_route_still_reaches_the_connector_for_public_urls(
assert "destination refused" not in r.text
assert r.status_code == 200, r.text
probe.assert_awaited_once()
+
+
+async def test_scheduler_owned_config_keys_do_not_reach_the_constructor(client: httpx.AsyncClient, monkeypatch: pytest.MonkeyPatch) -> None:
+ """A connector that has polled once carries scheduler state in its stored
+ ``connector_config`` — ``record_checkpoint`` writes ``checkpoint`` there,
+ beside ``poll_interval_seconds`` and ``filter_rules``. This route merged
+ the blob verbatim into the constructor, so the first recorded checkpoint
+ made every later test-connection answer 422 ("unexpected keyword argument
+ 'checkpoint'") on every connector whose ``__init__`` does not take it.
+ The exclusion is ``_connector_kwargs`` — the same set the scheduler uses —
+ so the next scheduler-only key cannot drift past this route either.
+ Pre-fix this test fails with exactly that 422; Splunk's ``__init__``
+ declares its keywords explicitly, so the stray key cannot be swallowed."""
+ from app.connectors.splunk import SplunkConnector
+
+ probe = AsyncMock(return_value={"success": True, "connector": "splunk", "version": "stub"})
+ monkeypatch.setattr(SplunkConnector, "test_connection", probe)
+ async with client as c:
+ r = await c.post(
+ "/api/v1/connectors/splunk/test",
+ headers={"Authorization": f"Bearer {_console_jwt('viewer')}"},
+ json={
+ "auth_config": {"token": "x"},
+ "connector_config": {
+ "base_url": "https://93.184.216.34:8089",
+ "ssl_verify": False,
+ # The scheduler-owned trio a polled connector accumulates.
+ "checkpoint": {"cursor": "2026-10-29T00:00:00Z"},
+ "poll_interval_seconds": 120,
+ "filter_rules": [{"field": "severity", "op": "gte", "value": "high"}],
+ },
+ },
+ )
+ assert r.status_code == 200, r.text
+ probe.assert_awaited_once()