Skip to content

Scrub nested secrets with the default event scrubber - #7624

Open
gyanu2507 wants to merge 2 commits into
getsentry:masterfrom
gyanu2507:fix/scrub-nested-secrets
Open

gyanu2507 wants to merge 2 commits into
getsentry:masterfrom
gyanu2507:fix/scrub-nested-secrets

Conversation

@gyanu2507

Copy link
Copy Markdown
Contributor

Fixes #7620.

The client built EventScrubber with recursive left at its default of False. A top-level password was removed. The same key under extra, request.data, or a breadcrumb was not.

The default scrubber now walks nested dicts and lists. EventScrubber(recursive=False) still does the shallow pass if you construct one yourself.

The client built EventScrubber with recursive left off, so a password under extra or request data stayed in the event. The default scrubber now walks nested dicts and lists.

Fixes getsentry#7620.
@gyanu2507
gyanu2507 requested a review from a team as a code owner September 23, 2026 01:59

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/client.py
Recursive scrubbing was writing into the caller's dicts. Nested containers are copied first. PyMongo's operation_ids.session is an id, not a secret, so it stays.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ac1726e. Configure here.

Comment thread sentry_sdk/scrubber.py
# walking them so scrubbing the event does not change that data.
if isinstance(v, (dict, list)):
v = copy.deepcopy(v)
d[k] = v

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deepcopy can skip remaining secrets

Medium Severity

copy.deepcopy runs on every nested dict or list before that subtree is walked. Extra and request payloads often hold ordinary Python objects that cannot be deep-copied, and that exception is swallowed by capture_internal_exceptions, so the rest of that scrub pass never runs and later denylist keys in the same section are sent unfiltered.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ac1726e. Configure here.

Comment thread sentry_sdk/scrubber.py
# Nested containers are often the caller's objects. Copy before
# walking them so scrubbing the event does not change that data.
if isinstance(v, (dict, list)):
v = copy.deepcopy(v)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's wise to start copying every event

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.

Default EventScrubber uses recursive=False, so nested denylist keys are not scrubbed |

2 participants