Skip to content

ref(integrations): route HTTP header filtering through data collection config - #6788

Merged
ericapisani merged 26 commits into
masterfrom
py-2584-update-wsgi-filter-headers
Jul 22, 2026
Merged

ref(integrations): route HTTP header filtering through data collection config#6788
ericapisani merged 26 commits into
masterfrom
py-2584-update-wsgi-filter-headers

Make changes to adjust to the data collection option being within the…

a590c8e
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: find-bugs completed Jul 9, 2026 in 0s

2 issues

find-bugs: Found 2 issues (1 medium, 1 low)

Medium

Allowlist header filtering substitutes `host`, corrupting event URL construction - `sentry_sdk/data_collection.py:109`

When data_collection.http_headers.request is configured in allowlist mode and "host" is not among the allowed terms, _filter_headers (in _wsgi_common.py) legitimately substitutes the host value with "[Filtered]". However, _get_request_data and _get_request_attributes in _asgi_common.py then pass headers.get("host") — now the substituted string "[Filtered]" — directly into _get_url. Because "[Filtered]" is truthy, _get_url builds URLs such as http://[Filtered]/path instead of falling back to the ASGI server field, corrupting the reported request URL. Previously host was never filtered (it is not in SENSITIVE_HEADERS), so this is a regression introduced by routing header filtering through the data-collection config. The fix belongs in _asgi_common.py: derive the host used for URL construction from the raw headers/scope rather than from the scrubbed headers.

Low

Test branching on string test-ID instead of `expected is None`, silently breaks on rename - `tests/integrations/aiohttp/test_aiohttp.py:1410-1414`

The if request.node.callspec.id == "data_collection_off_does_not_add_headers": guard should instead use if expected is None:. If the parametrize ID is ever renamed, the condition silently falls through to the else branch and immediately raises TypeError: 'NoneType' object is not subscriptable on expected["authorization"], producing a confusing failure rather than the intended assertion about absent headers.


⏱ 12m 4s · 1.3M in / 127.8k out · $3.62

Annotations

Check warning on line 109 in sentry_sdk/data_collection.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: find-bugs

Allowlist header filtering substitutes `host`, corrupting event URL construction

When `data_collection.http_headers.request` is configured in allowlist mode and `"host"` is not among the allowed terms, `_filter_headers` (in `_wsgi_common.py`) legitimately substitutes the host value with `"[Filtered]"`. However, `_get_request_data` and `_get_request_attributes` in `_asgi_common.py` then pass `headers.get("host")` — now the substituted string `"[Filtered]"` — directly into `_get_url`. Because `"[Filtered]"` is truthy, `_get_url` builds URLs such as `http://[Filtered]/path` instead of falling back to the ASGI `server` field, corrupting the reported request URL. Previously host was never filtered (it is not in `SENSITIVE_HEADERS`), so this is a regression introduced by routing header filtering through the data-collection config. The fix belongs in `_asgi_common.py`: derive the host used for URL construction from the raw headers/scope rather than from the scrubbed headers.