Skip to content

fix(scrubbing): leave query params the SDK does not redact untouched - #1200

Merged
solnic merged 1 commit into
feat/spec-conformant-param-scrubbingfrom
fix/scrub-query-string-placeholder
Sep 11, 2026
Merged

fix(scrubbing): leave query params the SDK does not redact untouched#1200
solnic merged 1 commit into
feat/spec-conformant-param-scrubbingfrom
fix/scrub-query-string-placeholder

Conversation

@solnic

@solnic solnic commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Now scrub_query_string/2 rewrites a parameter only when it redacts its value, so we won't end up with %2A, that would violate DC specs.

Before

  • query_string — the one redacted parameter reads password=%2A%2A%2A%2A%2A%2A%2A%2A%2A
pr4-conn-dump-before

After

  • query_string — the placeholder intact and everything the SDK keeps passed through
pr4-conn-dump-after

@solnic
solnic added this pull request to stack #1199 September 9, 2026 08:36
@solnic
solnic marked this pull request as ready for review September 9, 2026 12:13
@solnic
solnic force-pushed the fix/scrub-query-string-placeholder branch from e392227 to ed80cfe Compare September 9, 2026 12:39
Comment thread lib/sentry/scrubber.ex
end
end)
|> URI.encode_query()
|> String.split("&")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are you not using URI.decode_query/1 here (and below) because it'd lose ordering?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes we want to preserve original state, order included, and also prevent cases like ending up with ********* placeholder being converted to %2A%2A%2A%2A%2A%2A%2A%2A%2A.

Comment thread lib/sentry/scrubber.ex
defp decode_www_form(value) do
URI.decode_www_form(value)
rescue
ArgumentError -> value

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When does this raise?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good question - in my testing nowhere, but BugBot pointed out that if it did, we'd have an unwanted crash. It is very defensive, I have to admit - do you think it's 100% safe to remove that rescue?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@whatyouhide whatyouhide left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just some comments here.

@solnic
solnic force-pushed the fix/scrub-query-string-placeholder branch from ed80cfe to a22eaab Compare September 10, 2026 13:29
@solnic
solnic force-pushed the fix/scrub-query-string-placeholder branch from a22eaab to 8a9b84e Compare September 10, 2026 13:50
Comment thread lib/sentry/scrubber.ex
defp scrub_query_pair(pair, keys) do
case String.split(pair, "=", parts: 2) do
[raw_key, raw_value] ->
if redact_param?(decode_www_form(raw_key), decode_www_form(raw_value), keys) do

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The scrub_query_string implementation calls String.downcase on keys that may be non-UTF-8 binaries, causing a UnicodeConversionError and crashing the scrubber.
Severity: HIGH

Suggested Fix

The call to String.downcase within sensitive_key? should be wrapped in a try/rescue block to handle potential UnicodeConversionError. When an error is caught, the function should treat the key as a non-sensitive binary and proceed without attempting to downcase it, preventing the crash.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: lib/sentry/scrubber.ex#L345

Potential issue: The `scrub_query_string` function processes query strings by decoding
them with `decode_www_form`. If a key contains percent-encoded non-UTF-8 bytes (e.g.,
`%FF%FE`), `URI.decode_www_form` produces a non-UTF-8 binary. This binary is then passed
to `sensitive_key?`, which calls `String.downcase`. `String.downcase` raises a
`UnicodeConversionError` on non-UTF-8 input. The existing `rescue` block only catches
`ArgumentError`, so the `UnicodeConversionError` is unhandled and will crash the
scrubber process. This will cause a test at `test/sentry/scrubber_test.exs:176` to fail.

Did we get this right? 👍 / 👎 to inform future reviews.

@solnic
solnic merged commit 84a4c0d into master Sep 11, 2026
16 checks passed
@solnic
solnic deleted the fix/scrub-query-string-placeholder branch September 11, 2026 12:31
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.

3 participants