Skip to content

EventScrubber's header entries in DEFAULT_DENYLIST never match request headers #8272

Closed

Description

@ratomirjovanovic

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_headers strips only the names in SENSITIVE_ENV_KEYS, and X_CSRFTOKEN isn't one of them. So Django's X-CSRFToken header goes out as is, although the scrubber lists it.
  • With send_default_pii=True, _filter_headers keeps everything, and X-Api-Key and X-CSRFToken aren'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.

Activity

  1. linear-code commented on Nov 15, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 15, 2026
  3. sentrivana commented on Nov 17, 2026

    @sentrivana
    Collaborator

    Hey @ratomirjovanovic, thanks for reporting. The proposed way forward sounds good to me, feel free to open a PR.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 17, 2026
  5. self-assigned this
    on Nov 18, 2026
  6. added a commit that references this issue on Nov 18, 2026
    12c302b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions