: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(custom): treat a malformed OAuth2 integration id as not found (#74778)
Tom Owers5c7fedd05fe9
diff --git a/products/warehouse_sources/backend/models/custom_oauth2_integration.py b/products/warehouse_sources/backend/models/custom_oauth2_integration.pyindex 8791fc99035b..bd1465123718 100644--- a/products/warehouse_sources/backend/models/custom_oauth2_integration.py+++ b/products/warehouse_sources/backend/models/custom_oauth2_integration.py@@ -2,6 +2,7 @@ import timefrom datetime import UTC, datetime, timedeltafrom typing import TYPE_CHECKING, Optional+from django.core.exceptions import ValidationErrorfrom django.db import models, transactionfrom django.db.models import Q@@ -212,6 +213,11 @@ def get_custom_oauth2_integration(integration_id: str, team_id: int) -> CustomOA"""Load a custom OAuth2 integration for a team, outside request context (Temporal activities).Uses `for_team()` — the prescribed fail-closed escape hatch — so a caller can never read another- team's credentials by id. Raises `CustomOAuth2Integration.DoesNotExist` when the id isn't this team's.+ team's credentials by id. Raises `CustomOAuth2Integration.DoesNotExist` when the id isn't this+ team's, or isn't even a well-formed UUID (a malformed id can never match a row, so every caller+ already treats this the same as a genuinely missing row)."""- return CustomOAuth2Integration.objects.for_team(team_id).get(id=integration_id)+ try:+ return CustomOAuth2Integration.objects.for_team(team_id).get(id=integration_id)+ except ValidationError as exc:+ raise CustomOAuth2Integration.DoesNotExist(f"Invalid integration id: {integration_id!r}") from excdiff --git a/products/warehouse_sources/backend/tests/test_custom_oauth2_integration.py b/products/warehouse_sources/backend/tests/test_custom_oauth2_integration.pyindex 810c7aa4f13a..7ee4dae34bc1 100644--- a/products/warehouse_sources/backend/tests/test_custom_oauth2_integration.py+++ b/products/warehouse_sources/backend/tests/test_custom_oauth2_integration.py@@ -237,6 +237,13 @@ class TestCustomOAuth2Integration(BaseTest):with self.assertRaises(CustomOAuth2Integration.DoesNotExist):get_custom_oauth2_integration(str(other_integration.pk), self.team.pk)+ def test_malformed_id_raises_does_not_exist(self):+ # A malformed id used to hit the UUID field lookup unguarded, raising a raw+ # `django.core.exceptions.ValidationError` that none of this helper's callers catch — it escaped+ # as an unhandled error instead of the `DoesNotExist` every caller already handles gracefully.+ with self.assertRaises(CustomOAuth2Integration.DoesNotExist):+ get_custom_oauth2_integration("not-a-uuid", self.team.pk)+def test_admin_get_queryset_reads_outside_team_scope(self):# Django admin runs outside request/team scope, so the model's fail-closed default manager would# raise TeamScopeError the moment the changelist evaluates the queryset. The admin's get_queryset()