Skip to content

Commit 3c35fc4

Browse files
kconsroaga
authored andcommitted
fix(aci): 404 for non-digit IDs in endpoints (#92087)
Change our URL regexes to only recognize numeric IDs. This doesn't avoid issues from >2**64 numbers, but we can come back with a Model.id-bounds-aware ID parser on all endpoints if that ends up mattering. Fixes #92083
1 parent 46b94ca commit 3c35fc4

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/sentry/workflow_engine/endpoints/urls.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
organization_urlpatterns = [
3030
re_path(
31-
r"^(?P<organization_id_or_slug>[^\/]+)/detectors/(?P<detector_id>[^\/]+)/$",
31+
r"^(?P<organization_id_or_slug>[^\/]+)/detectors/(?P<detector_id>\d+)/$",
3232
OrganizationDetectorDetailsEndpoint.as_view(),
3333
name="sentry-api-0-organization-detector-details",
3434
),
@@ -43,12 +43,12 @@
4343
name="sentry-api-0-organization-detector-index",
4444
),
4545
re_path(
46-
r"^(?P<organization_id_or_slug>[^\/]+)/workflows/(?P<workflow_id>[^\/]+)/$",
46+
r"^(?P<organization_id_or_slug>[^\/]+)/workflows/(?P<workflow_id>\d+)/$",
4747
OrganizationWorkflowDetailsEndpoint.as_view(),
4848
name="sentry-api-0-organization-workflow-details",
4949
),
5050
re_path(
51-
r"^(?P<organization_id_or_slug>[^\/]+)/workflows/(?P<workflow_id>[^\/]+)/group-history$",
51+
r"^(?P<organization_id_or_slug>[^\/]+)/workflows/(?P<workflow_id>\d+)/group-history$",
5252
OrganizationWorkflowGroupHistoryEndpoint.as_view(),
5353
name="sentry-api-0-organization-workflow-group-history",
5454
),
@@ -68,7 +68,7 @@
6868
name="sentry-api-0-organization-detector-workflow-index",
6969
),
7070
re_path(
71-
r"^(?P<organization_id_or_slug>[^\/]+)/detector-workflow/(?P<detector_workflow_id>[^\/]+)/$",
71+
r"^(?P<organization_id_or_slug>[^\/]+)/detector-workflow/(?P<detector_workflow_id>\d+)/$",
7272
OrganizationDetectorWorkflowDetailsEndpoint.as_view(),
7373
name="sentry-api-0-organization-detector-workflow-details",
7474
),

tests/sentry/workflow_engine/endpoints/test_organization_detector_details.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from sentry.snuba.dataset import Dataset
1515
from sentry.snuba.models import QuerySubscription, SnubaQuery, SnubaQueryEventType
1616
from sentry.snuba.subscriptions import create_snuba_query, create_snuba_subscription
17+
from sentry.testutils.asserts import assert_status_code
1718
from sentry.testutils.cases import APITestCase
1819
from sentry.testutils.outbox import outbox_runner
1920
from sentry.testutils.silo import assume_test_silo_mode, region_silo_test
@@ -91,6 +92,15 @@ def test_simple(self):
9192
def test_does_not_exist(self):
9293
self.get_error_response(self.organization.slug, 3, status_code=404)
9394

95+
def test_malformed_id(self):
96+
from django.urls import reverse
97+
98+
# get_error_response can't generate an invalid URL, so we have to
99+
# generate a correct one and replace the valid ID with an invalid one.
100+
good_url = reverse(self.endpoint, args=[self.organization.slug, 7654])
101+
bad_url = good_url.replace("7654", "not-an-id")
102+
assert_status_code(self.client.get(bad_url), 404)
103+
94104

95105
@region_silo_test
96106
class OrganizationDetectorDetailsPutTest(OrganizationDetectorDetailsBaseTest):

tests/sentry/workflow_engine/endpoints/test_organization_workflow_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_audit_entry(self):
9696

9797
def test_does_not_exist(self):
9898
with outbox_runner():
99-
response = self.get_error_response(self.organization.slug, -1)
99+
response = self.get_error_response(self.organization.slug, 999999999)
100100
assert response.status_code == 404
101101

102102
# Ensure it wasn't deleted

0 commit comments

Comments
 (0)