Repository navigation
fix(scrubber): Match hyphenated header keys against the denylist - #8305
Draft
ratomirjovanovic wants to merge 2 commits into
Draft
ratomirjovanovic wants to merge 2 commits into
ratomirjovanovic wants to merge 2 commits into
Conversation
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.
sentrivana
requested changes
Nov 17, 2026
Collaborator
There was a problem hiding this comment.
Thanks @ratomirjovanovic, requesting two small changes, otherwise looks good to me.
Edited to add: Please check the failing tests, too.
Comment on lines
+62
to
+63
| def _normalize_key(key: str) -> str: | ||
| return key.lower().replace("-", "_") |
Collaborator
There was a problem hiding this comment.
Let's make this a private method of the EventScrubber please
Comment on lines
+90
to
+92
| # Header keys reach the scrubber hyphenated ("X-Api-Key"), while several | ||
| # entries use WSGI environ spelling ("x_api_key"), so compare both sides | ||
| # with hyphens and underscores folded together. |
Collaborator
There was a problem hiding this comment.
Suggested change
| # Header keys reach the scrubber hyphenated ("X-Api-Key"), while several | |
| # entries use WSGI environ spelling ("x_api_key"), so compare both sides | |
| # with hyphens and underscores folded together. |
It's pretty self-explanatory without the comment, let's remove it
Make the key normalizer a private method of EventScrubber, drop the redundant comment and the AnnotatedValue skip. Update the WSGI and ASGI tests whose expectations assumed that header names such as X-Forwarded-For and remote-addr were never matched by the denylist.
Author
|
Pushed both changes. The CI failures came from the new matching also hitting X-Forwarded-For and remote-addr when PII is off, so I updated those test expectations. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Several entries in
DEFAULT_DENYLISTuse WSGI environ spelling (x_csrftoken,x_api_key,set_cookie), but request headers reachEventScrubberhyphenated (X-Csrftoken) or lowercase with hyphens (x-api-key), so those entries never matched a header.scrub_dictnow folds hyphens and underscores together on both sides of the comparison, so a customdenylist=["x-api-key"]matches either spelling as well.Follow-ups this needs, as discussed in the issue:
x_forwarded_forwas inDEFAULT_DENYLISTand inDEFAULT_PII_DENYLIST. With matching fixed it would be scrubbed even withsend_default_pii=True, so it is removed from the first list and stays PII-only.send_default_pii=False, the PII list now also matches headers:X-Forwarded-For,X-Real-Ipandremote-addr(added by ASGI test clients) show up as[Filtered]. I updated the WSGI and ASGI tests that assumed they were never matched.Tests added in
tests/test_scrubber.py(hyphenated headers withsend_default_piion and off, custom denylist with either spelling). The new tests fail on master and pass with this change.Verified locally:
tests/test_scrubber.pyand thewsgi,asgiandflaskintegration suites (314 passed), plusruff check,ruff format --checkandmypyon the changed files. I could not runaws_lambdatests locally; the one that failed in CI already expects[Filtered], so it should pass again.Issues