Skip to content

fix(scrubber): Match hyphenated header keys against the denylist - #8305

Draft
ratomirjovanovic wants to merge 1 commit into
getsentry:masterfrom
ratomirjovanovic:fix/scrubber-header-keys
Draft

ratomirjovanovic wants to merge 1 commit into
getsentry:masterfrom
ratomirjovanovic:fix/scrubber-header-keys

Conversation

@ratomirjovanovic

Copy link
Copy Markdown

Description

Several entries in DEFAULT_DENYLIST use WSGI environ spelling (x_csrftoken, x_api_key, set_cookie), but request headers reach EventScrubber hyphenated (X-Csrftoken) or lowercase with hyphens (x-api-key), so those entries never matched a header. scrub_dict now folds hyphens and underscores together on both sides of the comparison, so a custom denylist=["x-api-key"] matches either spelling as well.

Two follow-ups that the new matching needs, both discussed in the issue:

  • x_forwarded_for was in DEFAULT_DENYLIST and in DEFAULT_PII_DENYLIST. With matching fixed it would be scrubbed even with send_default_pii=True, so it is removed from the first list and stays PII-only.
  • scrub_dict leaves a value alone when it is already an AnnotatedValue, so a header emptied by _filter_headers keeps its original annotation instead of being replaced by the scrubber's.

Tests added in tests/test_scrubber.py (hyphenated headers with send_default_pii on and off, custom denylist with either spelling). The new tests fail on master and pass with this change.

Verified locally: tests/test_scrubber.py, tests/integrations/wsgi and tests/integrations/asgi (97 passed, 1 skipped), plus ruff check, ruff format --check and mypy on the changed files. I did not run the framework integration suites that need their own tox environments.

Issues

Several default denylist entries use WSGI environ spelling (x_csrftoken,
x_api_key, set_cookie), while request headers reach the scrubber
hyphenated ("X-Csrftoken") or lowercase with hyphens ("x-api-key"), so
those entries never matched. Fold hyphens and underscores together on
both sides of the comparison.

x_forwarded_for was listed in DEFAULT_DENYLIST as well as in
DEFAULT_PII_DENYLIST, which would now scrub it even with
send_default_pii=True, so drop it from the first list. Also leave a
value alone when it is already an AnnotatedValue, so a header emptied by
_filter_headers keeps its original annotation.

This branch has not been deployed

No deployments
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.

EventScrubber's header entries in DEFAULT_DENYLIST never match request headers

1 participant