Skip to content

feat(wsgi): Add sentry.is_localhost for inbound filters - #7780

Merged
sentrivana merged 2 commits into
masterfrom
ivana/is-localhost-1-wsgi
Sep 30, 2026
Merged

sentrivana merged 2 commits into
masterfrom
ivana/is-localhost-1-wsgi

Conversation

@sentrivana

@sentrivana sentrivana commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ 130251 passed | ⏭️ 7169 skipped | Total: 137420 | Pass Rate: 94.78% | Execution Time: 436m 12s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +949
Passed Tests 📈 +950
Failed Tests 📉 -1
Skipped Tests —

➖ Removed Tests (1)

View removed tests
  • test_cache_spans_decorator[True]
    • File: tests.integrations.django.test_cache_module

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2554 uncovered lines.
❌ Project coverage is 90.26%. Comparing base (2a499ec) to head (c734878).

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

Comment thread sentry_sdk/integrations/wsgi.py Outdated
Comment thread sentry_sdk/integrations/wsgi.py Outdated
Comment thread tests/integrations/wsgi/test_wsgi.py
Comment thread tests/integrations/wsgi/test_wsgi.py
Comment thread sentry_sdk/integrations/wsgi.py Outdated
Comment thread sentry_sdk/integrations/wsgi.py Outdated
Comment thread sentry_sdk/integrations/wsgi.py Outdated
Comment thread sentry_sdk/integrations/wsgi.py Outdated
Comment thread sentry_sdk/utils.py
Comment thread sentry_sdk/utils.py
Comment thread tests/integrations/wsgi/test_wsgi.py
Comment thread tests/test_utils.py
Comment thread tests/test_utils.py
@sentrivana
sentrivana force-pushed the ivana/is-localhost-1-wsgi branch from abb80cf to 9426a24 Compare September 30, 2026 08:23
@sentrivana
sentrivana added this pull request to stack #7782 September 30, 2026 08:28
@sentrivana
sentrivana marked this pull request as ready for review September 30, 2026 08:35
@sentrivana
sentrivana requested a review from a team as a code owner September 30, 2026 08:35
Comment thread sentry_sdk/utils.py Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread sentry_sdk/integrations/wsgi.py
Comment thread sentry_sdk/integrations/wsgi.py
Comment thread sentry_sdk/utils.py
Comment on lines +2241 to +2243
domain = header_val.split(":")[0]
if _host_matches_local_domain(domain):
return True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
  • SentryWsgiMiddleware passes the client IP, SERVER_NAME, HTTP_HOST, and HTTP_X_FORWARDED_HOST to _is_localhost.
  • _is_localhost checks 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 accepts localhost and 127.0.0.1, so ::1 would 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

Comment thread sentry_sdk/utils.py
Comment thread sentry_sdk/utils.py
Comment on lines +103 to +104
_LOCAL_IPS = frozenset({"127.0.0.1", "::1"})
_LOCAL_DOMAINS = frozenset({"localhost", "127.0.0.1"})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_IPS includes ::1, but _LOCAL_DOMAINS is only localhost and 127.0.0.1.
  • _is_localhost() strips ports with header_val.split(":")[0] before _host_matches_local_domain().
  • For [::1]:8080, that yields [, which does not match; bare ::1 is 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-1345
  • sentry_sdk/utils.py:2241-2243
  • tests/test_utils.py:1433-1439

Identified by Warden · find-bugs · HAM-7BK

@sentrivana
sentrivana merged commit f0438d3 into master Sep 30, 2026
314 of 316 checks passed
@sentrivana
sentrivana deleted the ivana/is-localhost-1-wsgi branch September 30, 2026 09:12
gricha added a commit to getsentry/warden that referenced this pull request Sep 30, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants