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(slack-app): never unfurl links in slack connect channels (#117059)

Vojta Bartoš19cc0a936e61
diff --git a/products/slack_app/backend/api.py b/products/slack_app/backend/api.py
index f2445b619d06..2160514d12d9 100644
--- a/products/slack_app/backend/api.py
+++ b/products/slack_app/backend/api.py
@@ -2970,6 +2970,13 @@ def route_posthog_code_event_to_relevant_region(
incoming_host=incoming_host,
)
+ # Never unfurl into a Slack Connect channel, even an approved one. A card or its chart shows project
+ # data to people outside the organization, and a pasted link is not a request for it. Every region
+ # drops the event the same way, so this runs before any lookup or cross-region forward.
+ if event_type == "link_shared" and is_ext_shared_channel:
+ logger.info("slack_link_unfurl_external_channel", slack_team_id=slack_team_id, channel=event.get("channel"))
+ return ROUTE_HANDLED_LOCALLY
+
# The link's own host decides the region, from URL parsing alone — ahead of ``load_integrations``,
# whose query and Slack auth check would be thrown away on the forward. A workspace connected in
# both regions otherwise resolves a `us.` link's `/project/:id` against this region's project of
@@ -3022,16 +3029,6 @@ def route_posthog_code_event_to_relevant_region(
):
return _proxy_event_and_return_route(request, other_domain)
if event_type == "link_shared":
- # Mirror the app_mention gate: don't unfurl project data into an unapproved externally
- # shared channel. A paste isn't an explicit invocation, so suppress without prompting.
- channel_id = event.get("channel") if isinstance(event.get("channel"), str) else None
- if (
- is_ext_shared_channel
- and channel_id
- and not _channel_is_approved(local_match.integration_id, channel_id)
- ):
- logger.info("slack_link_unfurl_channel_unapproved", slack_team_id=slack_team_id, channel=channel_id)
- return ROUTE_HANDLED_LOCALLY
handle_posthog_link_unfurl(event, local_match)
return ROUTE_HANDLED_LOCALLY
return _route_to_other_region_or_drop(request, slack_team_id, proxied=proxied, other_domain=other_domain)
diff --git a/products/slack_app/backend/tests/test_link_unfurl.py b/products/slack_app/backend/tests/test_link_unfurl.py
index a3e57373a3c6..e1e36a9a9d79 100644
--- a/products/slack_app/backend/tests/test_link_unfurl.py
+++ b/products/slack_app/backend/tests/test_link_unfurl.py
@@ -781,12 +781,12 @@ class TestLinkUnfurlChannelGate(TestCase):
@parameterized.expand(
[
("ext_unapproved", True, False, False),
- ("ext_approved", True, True, True),
+ ("ext_approved", True, True, False),
("internal_channel", False, False, True),
]
)
@patch("products.slack_app.backend.api.handle_posthog_link_unfurl")
- def test_unfurl_gated_on_external_channel_approval(
+ def test_unfurl_never_reaches_an_external_channel(
self, _name: str, is_ext_shared: bool, approved: bool, expect_unfurled: bool, mock_unfurl: MagicMock
) -> None:
if approved: