fix(scrubber): Scrub request bodies that are JSON arrays - #7561
Draft
Om-singhaI wants to merge 1 commit into
Draft
Om-singhaI wants to merge 1 commit into
Om-singhaI wants to merge 1 commit into
Conversation
scrub_request only called scrub_dict on event["request"]["data"], and scrub_dict returns immediately for anything that is not a dict, so a request body parsed as a top level JSON array was never scrubbed. Call the existing scrub_list helper on the body as well.
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
scrub_requestonly callsscrub_dictonevent["request"]["data"], andscrub_dictreturns immediately for anything that isn't a dict. So a body that parses to a top level JSON array is skipped entirely and every secret in it ships in the clear. It happens under the default scrubber, no config needed.scrub_listalready handles this shape. Its docstring says it walks a list and any nested lists and callsscrub_dicton every dictionary it finds, andscrub_dictalready hands nested lists to it whenrecursiveis on. It just was never called on the request body.What changed:
scrub_requestnow callsscrub_dictand thenscrub_listonevent["request"]["data"]. Each one ignores the type it doesn't handle, so dict bodies behave exactly as before.tests/test_scrubber.py, one for a list body under the default scrubber and one for a dict nested inside a list body withrecursive=True.One thing worth your call:
scrub_listrecurses into nested lists no matter whatrecursiveis set to, so[[{"password": "x"}]]now gets filtered where today it isn't. That only ever filters more, never less. If you'd rather keep the shallow path exact I can gate the call onself.recursiveinstead.Issues
resolves: #7543
Testing
pytest tests/test_scrubber.py13 passed, was 11 passed on masterpytest tests/integrations/wsgi/test_wsgi.py76 passedsentry_sdk/scrubber.pyfrom master and rerunning: both new tests fail,assert {'data': [{'token': 'secret', ...}]} == {'data': [{'token': '[Filtered]', ...}]}ruff checkandruff format --checkclean onsentry_sdk/scrubber.pyandtests/test_scrubber.py[{"password": "hunter2", "user": "a"}]to[{"password": "[Filtered]", "user": "a"}], object body unchanged at{"password": "[Filtered]", "user": "a"}