Repository navigation
fix(scrubber): Match hyphenated header keys against the denylist - #8305
Draft
ratomirjovanovic wants to merge 1 commit into
Draft
ratomirjovanovic wants to merge 1 commit into
ratomirjovanovic wants to merge 1 commit 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.
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.Two follow-ups that the new matching needs, both 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.scrub_dictleaves a value alone when it is already anAnnotatedValue, so a header emptied by_filter_headerskeeps its original annotation instead of being replaced by the scrubber's.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.py,tests/integrations/wsgiandtests/integrations/asgi(97 passed, 1 skipped), plusruff check,ruff format --checkandmypyon the changed files. I did not run the framework integration suites that need their own tox environments.Issues