Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend/integrations): reject webhook ingress on provider path mismatch (#13559)

Krzysztof Czerwinski646dd5b8cfad
diff --git a/autogpt_platform/backend/backend/api/features/integrations/router.py b/autogpt_platform/backend/backend/api/features/integrations/router.py
index 6ca19461fe..921a9c27eb 100644
--- a/autogpt_platform/backend/backend/api/features/integrations/router.py
+++ b/autogpt_platform/backend/backend/api/features/integrations/router.py
@@ -558,7 +558,23 @@ async def webhook_ingress_generic(
webhook_manager = get_webhook_manager(provider)
try:
webhook = await get_webhook(webhook_id, include_relations=True)
- user_id = webhook.user_id
+ # Sanity check: `provider` from URL and fetched webhook must match.
+ # Otherwise the URL provider's verifier runs instead of the webhook's
+ # own (a no-op for unsigned providers like Compass), bypassing it.
+ if webhook.provider.value.lower() != provider.value.lower():
+ logger.warning(
+ f"Webhook #{webhook_id} provider mismatch: "
+ f"registered as {webhook.provider.value}, ingress via {provider.value}"
+ )
+ # Same as the actual "webhook not found" response to conceal existence
+ raise NotFoundError(f"Webhook #{webhook_id} not found")
+ except NotFoundError as e:
+ logger.warning(f"Webhook payload received for unknown webhook #{webhook_id}")
+ raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e))
+ logger.debug(f"Webhook #{webhook_id}: {webhook}")
+
+ user_id = webhook.user_id
+ try:
credentials = (
await creds_manager.get(user_id, webhook.credentials_id)
if webhook.credentials_id
@@ -567,7 +583,6 @@ async def webhook_ingress_generic(
except NotFoundError as e:
logger.warning(f"Webhook payload received for unknown webhook #{webhook_id}")
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e))
- logger.debug(f"Webhook #{webhook_id}: {webhook}")
# Run provider signature verification (no-op for providers whose protocol
# has no signing scheme). 403 on failure; not 404 — that would leak
diff --git a/autogpt_platform/backend/backend/api/features/integrations/webhook_ingress_test.py b/autogpt_platform/backend/backend/api/features/integrations/webhook_ingress_test.py
index 403bf3bab0..aa0bf30e76 100644
--- a/autogpt_platform/backend/backend/api/features/integrations/webhook_ingress_test.py
+++ b/autogpt_platform/backend/backend/api/features/integrations/webhook_ingress_test.py
@@ -11,6 +11,8 @@ signature checks to each manager's `verify_signature`. This file pins:
* Generic webhook honors an optional `secret_token` on the triggered block:
passes through when unset, enforces when set.
* Providers without a signing scheme (Compass, Slant3D) pass through.
+* A webhook registered under one provider can't be processed via a different
+ provider's ingress path (the manager is selected from the URL provider).
* `verify_signature` runs before `validate_payload` (call ordering).
"""
@@ -445,6 +447,77 @@ class TestGenericWebhookOptionalToken:
assert resp.status_code != 403, resp.text
+# ---------------------------------------------------------------------------
+# Provider path confusion: URL provider must match the stored webhook.
+# ---------------------------------------------------------------------------
+
+
+class TestProviderPathConfusion:
+ """The ingress manager is selected from the URL `{provider}`, so a webhook
+ registered under one provider must not be processable via another
+ provider's path. Otherwise a secret-protected generic webhook's UUID,
+ routed through an unsigned provider path (Compass/Slant3D), would run that
+ provider's no-op verifier and bypass the configured `secret_token`.
+
+ A mismatch returns the same 404 as a nonexistent webhook: a distinct status
+ (e.g. 403) would confirm the ID exists under a different provider."""
+
+ def _run_cross_provider(
+ self, webhook, path_provider: str, url_manager_provider: ProviderName, **kwargs
+ ):
+ # Unlike `_run`, the manager comes from the URL path provider (what the
+ # real router does) rather than the stored webhook's provider — that
+ # divergence is the whole point of the attack being reproduced.
+ patches = _patch_ingress(webhook) + [
+ patch(
+ "backend.api.features.integrations.router.get_webhook_manager",
+ return_value=_manager(url_manager_provider),
+ )
+ ]
+ with ExitStack() as stack:
+ for p in patches:
+ stack.enter_context(p)
+ return _post(path_provider, **kwargs)
+
+ def _secret_protected_generic(self):
+ node = MagicMock()
+ node.input_default = {"secret_token": "t0ken"}
+ return _make_webhook(ProviderName("generic_webhook"), triggered_nodes=[node])
+
+ def test_generic_secret_not_bypassable_via_compass_path(self):
+ resp = self._run_cross_provider(
+ self._secret_protected_generic(), "compass", ProviderName.COMPASS
+ )
+ assert resp.status_code == 404, resp.text
+ # Response is indistinguishable from a genuinely nonexistent webhook.
+ assert resp.json()["detail"] == f"Webhook #{WEBHOOK_ID} not found"
+
+ def test_generic_secret_not_bypassable_via_slant3d_path(self):
+ resp = self._run_cross_provider(
+ self._secret_protected_generic(), "slant3d", ProviderName.SLANT3D
+ )
+ assert resp.status_code == 404, resp.text
+ assert resp.json()["detail"] == f"Webhook #{WEBHOOK_ID} not found"
+
+ def test_matching_provider_path_still_processes(self):
+ # Control: the same webhook on its own path with the correct secret is
+ # accepted — the guard rejects only provider mismatches.
+ resp = self._run_cross_provider(
+ self._secret_protected_generic(),
+ "generic_webhook",
+ ProviderName("generic_webhook"),
+ headers={"X-Webhook-Secret": "t0ken"},
+ )
+ assert resp.status_code == 200, resp.text
+
+ def test_matching_provider_different_case_accepted(self):
+ # The guard compares case-insensitively: a same-provider request whose
+ # path casing differs from the stored (canonical) value isn't rejected.
+ webhook = _make_webhook(ProviderName.COMPASS)
+ resp = self._run_cross_provider(webhook, "Compass", ProviderName.COMPASS)
+ assert resp.status_code == 200, resp.text
+
+
# ---------------------------------------------------------------------------
# Ordering: verify_signature runs BEFORE validate_payload.
# ---------------------------------------------------------------------------