Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(ingress): answer 403 again when a Slack or Mailgun secret is not set (#103807)

Julian Bez8f5890187831
diff --git a/posthog/ingress/README.md b/posthog/ingress/README.md
index 5192d818bfbe..60c2dc19f158 100644
--- a/posthog/ingress/README.md
+++ b/posthog/ingress/README.md
@@ -231,7 +231,7 @@ The same attribute answers a delivery whose consumers did not accept it, under o
Add a `<provider>/` subpackage with a `provider.py` holding three things (see `github/` for the full shape, `vapi/` for a small one):
- `SPECS` — one `ProviderSpec` per app, naming the event types the app is subscribed to. The registry validates consumers against these.
-- A `WebhookProvider` subclass — its `scheme()` (from `verify/`), its `deliveries()` (how to read event type, delivery id and context off the request), and any status codes its protocol fixes. The defaults are 403 on a bad signature, 500 when unconfigured, and 202 on success, with a short body naming the reason on the two rejections. An incarnation that answers 404 to withhold the endpoint's existence sets `explains_rejections = False` so the body stays empty as well. Three more attributes are optional: `parse()`, which decodes the body, `throttle_class`, which caps request volume, and `retry_status`, which a provider that redelivers on a non-2xx sets so an unaccepted delivery is not receipted. See [The lanes one request runs through](#the-lanes-one-request-runs-through).
+- A `WebhookProvider` subclass — its `scheme()` (from `verify/`), its `deliveries()` (how to read event type, delivery id and context off the request), and any status codes its protocol fixes. The defaults are 403 on a bad signature, 500 when unconfigured, and 202 on success, with a short body naming the reason on the two rejections. The 500 suits an endpoint whose secret is always set, because an unconfigured one is then an operator fault; an endpoint that a deployment may legitimately never configure, such as Slack and Mailgun on a self-hosted instance, sets `unconfigured_status = 403` instead, or the URL answers a server error to every anonymous probe. An incarnation that answers 404 to withhold the endpoint's existence sets `explains_rejections = False` so the body stays empty as well, and so does one that must not tell an unauthenticated caller whether the secret is merely unset. Three more attributes are optional: `parse()`, which decodes the body, `throttle_class`, which caps request volume, and `retry_status`, which a provider that redelivers on a non-2xx sets so an unaccepted delivery is not receipted. See [The lanes one request runs through](#the-lanes-one-request-runs-through).
- A `build_<provider>_provider(...)` function returning that provider, which the URLconf hands to `build_webhook_view()`.
A builder that takes an `app` name checks it with `require_known_app(provider, app, SPECS)` before anything else, so a typo raises `UnknownApp` at import. Without that check the endpoint builds and serves: consumers register against the declared app names, so nothing matches and every delivery is receipted and dropped, or the app has no secret getter and every delivery answers `NOT_CONFIGURED`.
diff --git a/posthog/ingress/mailgun/README.md b/posthog/ingress/mailgun/README.md
index ad3a92c8c10f..ad6f4cd2b28f 100644
--- a/posthog/ingress/mailgun/README.md
+++ b/posthog/ingress/mailgun/README.md
@@ -57,6 +57,10 @@ An unsigned caller therefore buys a full multipart parse for its 403, which is a
A forwarded delivery crosses as a rebuilt form rather than as the raw bytes, because the form read leaves none.
[Regional forwarding](../README.md#regional-forwarding) carries the rule, and a region-split consumer declares `ownership` as it would on any other provider.
+All three apps answer 403 when the signing key is unset, which is `unconfigured_status`, not the package default of 500.
+That is the status the hand-rolled views answered, and it keeps an instance that never connected an email channel from turning every anonymous probe of a public URL into a server error.
+`explains_rejections` is False with it, so neither rejection names its reason: which of the two a caller hit is an operator fact about the instance.
+
Mailgun's event webhooks (delivered, failed, opened) are a different payload shape, with the event name in the form.
They would be a third app, added when a product needs one.
diff --git a/posthog/ingress/mailgun/provider.py b/posthog/ingress/mailgun/provider.py
index 961a189e3ff6..842758571cba 100644
--- a/posthog/ingress/mailgun/provider.py
+++ b/posthog/ingress/mailgun/provider.py
@@ -63,6 +63,12 @@ class MailgunProvider(WebhookProvider):
# A route delivery carries the whole mail message, including up to MAX_FILES attachments, and
# the forward rebuilds and re-sends every part. Three seconds is not enough for that.
forward_timeout_seconds = 10.0
+ # The status these endpoints answered before they moved here: an instance with no signing key
+ # reads as a request it refuses, not as a server that broke.
+ unconfigured_status = 403
+ # The body must not tell an unauthenticated caller that the endpoint is unconfigured, which is
+ # an operator fact about an instance anyone can probe.
+ explains_rejections = False
def __init__(self, app: str, *, signing_key_getter: Callable[[], str | None]) -> None:
require_known_app(self.provider, app, SPECS)
diff --git a/posthog/ingress/slack/README.md b/posthog/ingress/slack/README.md
index 2e71ffe48b4c..d50d774eb4b8 100644
--- a/posthog/ingress/slack/README.md
+++ b/posthog/ingress/slack/README.md
@@ -45,6 +45,10 @@ The incarnation answers it in `pre_dispatch_response()`, before dispatch.
Slack redelivers a delivery it got a non-2xx for, so `retry_status` is 502: a workspace ownership lookup that raised or hit its timeout, a forward to the region that owns the workspace that did not land, and a receipt write that raised must not be receipted, or the event is lost.
On the interactivity endpoint that also keeps a click visible: Slack shows the person who clicked a delivery error rather than nothing.
+
+Both endpoints answer 403 when the signing secret is unset, which is `unconfigured_status`, not the package default of 500.
+That is the status the hand-rolled views answered, and it keeps an instance that never connected SupportHog from turning every anonymous probe of a public URL into a server error.
+`explains_rejections` is False with it, so neither rejection names its reason: which of the two a caller hit is an operator fact about the instance.
The other status codes are the defaults.
Interactive components are posted as a form with one `payload` field holding the JSON, so `SlackInteractivityProvider` overrides `parse()` and reads `request.POST`.
diff --git a/posthog/ingress/slack/provider.py b/posthog/ingress/slack/provider.py
index 5fb135681340..c41ac4e2cc3c 100644
--- a/posthog/ingress/slack/provider.py
+++ b/posthog/ingress/slack/provider.py
@@ -85,6 +85,12 @@ class SlackProvider(WebhookProvider):
# a workspace ownership lookup that raised or hit its timeout, a forward to the owning region
# that never landed, and a receipt write that raised all lose the 202.
retry_status = 502
+ # The status this endpoint answered before it moved here: an instance with no signing secret
+ # reads as a request it refuses, not as a server that broke.
+ unconfigured_status = 403
+ # The body must not tell an unauthenticated caller that the endpoint is unconfigured, which is
+ # an operator fact about an instance anyone can probe.
+ explains_rejections = False
def __init__(self, *, app: str = "supporthog", secret_getter: Callable[[], str | None]) -> None:
require_known_app(self.provider, app, SPECS)
diff --git a/posthog/ingress/test/test_providers.py b/posthog/ingress/test/test_providers.py
index 115609b2fdd2..7a7a4e67277a 100644
--- a/posthog/ingress/test/test_providers.py
+++ b/posthog/ingress/test/test_providers.py
@@ -1,15 +1,17 @@
from collections.abc import Callable, Mapping
from typing import Any
-from django.test import SimpleTestCase
+from django.http import HttpRequest
+from django.test import RequestFactory, SimpleTestCase
from parameterized import parameterized
from posthog.ingress.github.provider import build_github_provider
from posthog.ingress.mailgun.provider import build_mailgun_provider
from posthog.ingress.providers import UnknownApp, WebhookProvider
-from posthog.ingress.slack.provider import build_slack_provider
+from posthog.ingress.slack.provider import build_slack_interactivity_provider, build_slack_provider
from posthog.ingress.sns.provider import build_sns_provider
+from posthog.ingress.views import build_webhook_view
def _github(app: str) -> WebhookProvider:
@@ -66,3 +68,48 @@ class TestProviderAppNames(SimpleTestCase):
self, _provider: str, builder: Callable[[str], WebhookProvider], declared_app: str, _unknown_app: str
) -> None:
self.assertEqual(builder(declared_app).app, declared_app)
+
+
+def _no_secret() -> str | None:
+ return None
+
+
+def _json_post() -> HttpRequest:
+ return RequestFactory().post("/webhook/", data="{}", content_type="application/json")
+
+
+def _form_post() -> HttpRequest:
+ # Mailgun and Slack interactivity read a form, and Mailgun refuses any other content type
+ # before it looks at the secret at all.
+ return RequestFactory().post("/webhook/", data={"timestamp": "1", "token": "t", "signature": "s"})
+
+
+def _unconfigured_mailgun(app: str) -> WebhookProvider:
+ return build_mailgun_provider(app, signing_key_getter=_no_secret)
+
+
+# One row per endpoint that answered 403 for a missing secret before it moved into this package.
+UNCONFIGURED_ENDPOINTS = [
+ ("slack_events", lambda: build_slack_provider(secret_getter=_no_secret), _json_post),
+ ("slack_interactivity", lambda: build_slack_interactivity_provider(secret_getter=_no_secret), _form_post),
+ ("mailgun_inbound", lambda: _unconfigured_mailgun("inbound"), _form_post),
+ ("mailgun_outbound", lambda: _unconfigured_mailgun("outbound"), _form_post),
+ ("mailgun_capture", lambda: _unconfigured_mailgun("capture"), _form_post),
+]
+
+
+class TestUnconfiguredEndpoints(SimpleTestCase):
+ @parameterized.expand(UNCONFIGURED_ENDPOINTS)
+ def test_a_missing_secret_still_answers_403_with_no_reason(
+ self,
+ _name: str,
+ build_provider: Callable[[], WebhookProvider],
+ build_request: Callable[[], HttpRequest],
+ ) -> None:
+ response = build_webhook_view(build_provider())(build_request())
+
+ # The package default is 500, which would turn every anonymous probe of these public URLs
+ # into a server error on any instance that never set the secret.
+ self.assertEqual(response.status_code, 403)
+ # And the body must not tell that caller which of the two it was.
+ self.assertEqual(response.content, b"")