Skip to content

Commit 04046b8

Browse files
committed
fix(middleware): Skip OAuth endpoints in AI agent middleware
Exclude /oauth/ paths from the AI agent markdown response middleware since these are legitimate machine-to-machine endpoints that should work normally (device authorization, token exchange, etc.). Fixes feedback from #106485
1 parent 07e8bf8 commit 04046b8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/sentry/middleware/ai_agent.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class AIAgentMiddleware:
8383
and returns helpful markdown guidance instead of HTML.
8484
8585
Detection criteria:
86-
1. Request path does NOT start with /api/ (frontend routes only)
86+
1. Request path does NOT start with /api/ or /oauth/ (frontend routes only)
8787
2. Accept header contains text/markdown or text/x-markdown
8888
3. Request is anonymous (no authenticated user, no auth token)
8989
"""
@@ -96,6 +96,10 @@ def __call__(self, request: HttpRequest) -> HttpResponse:
9696
if request.path.startswith("/api/"):
9797
return self.get_response(request)
9898

99+
# Skip OAuth routes - legitimate machine-to-machine endpoints
100+
if request.path.startswith("/oauth/"):
101+
return self.get_response(request)
102+
99103
if not _accepts_markdown(request):
100104
return self.get_response(request)
101105

tests/sentry/middleware/test_ai_agent.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ def test_api_path_passes_through(self):
100100

101101
assert self.middleware(request).status_code == 401
102102

103+
def test_oauth_path_passes_through(self):
104+
request = self.make_anonymous_request("/oauth/token/", HTTP_ACCEPT="text/markdown")
105+
106+
assert self.middleware(request).status_code == 401
107+
103108
@patch("sentry.middleware.ai_agent.logger.info")
104109
def test_logs_request(self, mock_logger: MagicMock):
105110
request = self.make_anonymous_request(

0 commit comments

Comments
 (0)