Repository navigation
feat(wsgi): Add sentry.is_localhost for inbound filters - #7780
Conversation
Codecov Results 📊✅ 130251 passed | ⏭️ 7169 skipped | Total: 137420 | Pass Rate: 94.78% | Execution Time: 436m 12s 📊 Comparison with Base Branch
➖ Removed Tests (1)View removed tests
All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 2554 uncovered lines. Coverage diff@@ Coverage Diff @@
## master #PR +/-##
==========================================
- Coverage 90.28% 90.26% -0.02%
==========================================
Files 195 195 —
Lines 26197 26220 +23
Branches 9758 9774 +16
==========================================
+ Hits 23650 23666 +16
- Misses 2547 2554 +7
- Partials 1484 1484 —Generated by Codecov Action |
abb80cf to
9426a24
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9426a24. Configure here.
| domain = header_val.split(":")[0] | ||
| if _host_matches_local_domain(domain): | ||
| return True |
There was a problem hiding this comment.
IPv6 loopback Host headers are not classified as localhost
_is_localhost splits Host and X-Forwarded-Host values at the first colon, so [::1]:8080 becomes [ and fails the local-domain check. The check also does not recognize ::1 as a host domain, even without a port. Consequently, these headers are classified as non-local unless the client IP independently matches; parse bracketed IPv6 literals and recognize the loopback address.
Evidence
SentryWsgiMiddlewarepasses the client IP,SERVER_NAME,HTTP_HOST, andHTTP_X_FORWARDED_HOSTto_is_localhost._is_localhostchecks client IPs against_LOCAL_IPS, but splits each host header at the first colon before calling_host_matches_local_domain.- For
[::1]:8080, that split produces[. The matcher only acceptslocalhostand127.0.0.1, so::1would not match even if the brackets were parsed correctly. - With a non-loopback client IP, an IPv6 loopback host header therefore produces a false result.
Identified by Warden · code-review · WMM-RCU
| _LOCAL_IPS = frozenset({"127.0.0.1", "::1"}) | ||
| _LOCAL_DOMAINS = frozenset({"localhost", "127.0.0.1"}) |
There was a problem hiding this comment.
IPv6 loopback Host headers are not detected as localhost
_LOCAL_DOMAINS omits ::1, and host parsing uses split(":")[0], so Host values like [::1] or [::1]:8080 never match unless client_ip is already loopback.
Evidence
_LOCAL_IPSincludes::1, but_LOCAL_DOMAINSis onlylocalhostand127.0.0.1._is_localhost()strips ports withheader_val.split(":")[0]before_host_matches_local_domain().- For
[::1]:8080, that yields[, which does not match; bare::1is also not in_LOCAL_DOMAINS. - Tests cover
client_ip="::1"but not IPv6 Host / X-Forwarded-Host forms.
Also found at 3 additional locations
tests/integrations/wsgi/test_wsgi.py:1344-1345sentry_sdk/utils.py:2241-2243tests/test_utils.py:1433-1439
Identified by Warden · find-bugs · HAM-7BK
Raise the output budget for deduplication and cross-location comparisons from 512 to 8,192 tokens so reasoning models can finish their JSON responses. Truncation now reports `output_limit` with the model, finish reason, configured limit, and consumed tokens. Failed cross-location consolidation also emits a warning. #531 started enforcing previously ignored token limits. On [sentry-python#7780](getsentry/sentry-python#7780), Warden 0.50.0 exhausted the 512-token budget and fell back to hash matching, posting repeated findings despite the semantic-matching fix in #536. Regression tests exercise all three comparison paths through the Pi adapter using captured findings, retain an independent bug, and check truncation diagnostics and telemetry. A local replay using the production auxiliary model completed all seven comparisons at 8,192 tokens; the 512-token control truncated five. The replay absorbed the 14 duplicate initial findings and reduced four follow-up comments to one new IPv6 finding, without posting to GitHub. Co-authored-by: GPT-6 <noreply@anthropic.com>

Mirrors https://github.com/getsentry/relay/blob/master/relay-filter/src/localhost.rs
Part 1 of #7727