-
-
Notifications
You must be signed in to change notification settings - Fork 216
fix(scrubbing): leave query params the SDK does not redact untouched #1200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,15 +332,37 @@ defmodule Sentry.Scrubber do | |
| keys = param_keys(opts) | ||
|
|
||
| query | ||
| |> URI.query_decoder() | ||
| |> Enum.map(fn {key, value} -> | ||
| cond do | ||
| sensitive_key?(key, keys) -> {key, @scrubbed_value} | ||
| is_binary(value) and value =~ credit_card_regex() -> {key, @scrubbed_value} | ||
| true -> {key, value} | ||
| end | ||
| end) | ||
| |> URI.encode_query() | ||
| |> String.split("&") | ||
| |> Enum.map_join("&", &scrub_query_pair(&1, keys)) | ||
| end | ||
|
|
||
| # Only a redacted pair is rewritten. Everything the SDK keeps is passed | ||
| # through exactly as it arrived, so the reported query string still matches | ||
| # what the client sent rather than a re-encoding of it. | ||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixThe call to Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| raw_key <> "=" <> @scrubbed_value | ||
| else | ||
| pair | ||
| end | ||
|
|
||
| [_without_value] -> | ||
| pair | ||
| end | ||
| end | ||
|
|
||
| defp redact_param?(key, value, keys) do | ||
| sensitive_key?(key, keys) or value =~ credit_card_regex() | ||
| end | ||
|
|
||
| # Scrubbing runs while an error is already being reported, so malformed | ||
| # percent-encoding must not raise. The raw form is still fine to match on. | ||
| defp decode_www_form(value) do | ||
| URI.decode_www_form(value) | ||
| rescue | ||
| ArgumentError -> value | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When does this raise?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| end | ||
|
|
||
| @doc """ | ||
|
|
||
There was a problem hiding this comment.
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/1here (and below) because it'd lose ordering?There was a problem hiding this comment.
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.