Repository navigation
Description
The "wsgi" entries in DEFAULT_DENYLIST (sentry_sdk/scrubber.py) are spelled with underscores: x_csrftoken, x_api_key, set_cookie, x_forwarded_for, and x_real_ip in DEFAULT_PII_DENYLIST. scrub_dict compares k.lower() against the list, but the request headers it gets are hyphenated. _werkzeug._get_headers turns HTTP_X_CSRFTOKEN into X-Csrftoken, and _asgi_common._get_headers keeps the raw x-api-key. So x-csrftoken is never equal to x_csrftoken and these entries never fire on headers. proxy-authorization right next to them uses a hyphen, which makes me think the rest are just WSGI environ names that got lowercased.
What reaches Sentry because of it:
- With the default
send_default_pii=False,_filter_headersstrips only the names inSENSITIVE_ENV_KEYS, andX_CSRFTOKENisn't one of them. So Django'sX-CSRFTokenheader goes out as is, although the scrubber lists it. - With
send_default_pii=True,_filter_headerskeeps everything, andX-Api-KeyandX-CSRFTokenaren't scrubbed even though they are in the security denylist that's supposed to apply regardless of PII.
Checked on master (26ef571): capture_event with {"X-Csrftoken": ..., "x-api-key": ..., "Set-Cookie": ...} request headers keeps all three values, with send_default_pii on and off.
Normalizing both sides in EventScrubber (e.g. x.lower().replace("-", "_") for the denylist and the same for the key in scrub_dict) fixes it, and a user-supplied denylist=["x-api-key"] then matches either spelling. One catch I hit while trying it: x_forwarded_for is in DEFAULT_DENYLIST too, not only in DEFAULT_PII_DENYLIST, so once keys match, X-Forwarded-For gets scrubbed even with send_default_pii=True. test_request_headers_legacy_pii_passes_headers_through and test_request_headers_legacy_no_pii_redacts_sensitive in tests/integrations/wsgi/test_wsgi.py rely on it not matching (the second one's docstring says so). So I'd also drop x_forwarded_for from DEFAULT_DENYLIST and leave it to the PII list. The no-PII test would then see the scrubber's [Filtered] on top of the emptied value from _filter_headers, unless you'd rather have the scrubber skip values that are already an AnnotatedValue.
This scrubs more than today, so I wanted to check the direction before sending a PR. Happy to do it with tests in tests/test_scrubber.py.
Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Nov 15, 2026
PY-3078
sentrivana commentedon Nov 17, 2026
Hey @ratomirjovanovic, thanks for reporting. The proposed way forward sounds good to me, feel free to open a PR.
fix(scrubber): Match hyphenated header keys against the denylist (get…