Skip to content
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

Adds support for lists in scrubbing logic #442

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/sentry/plug_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ defmodule Sentry.PlugContext do
end

@doc """
Recursively scrubs a map that may have nested maps
Recursively scrubs a map that may have nested maps or lists

Accepts a list of keys to scrub, and a list of options to configure

Expand Down Expand Up @@ -206,11 +206,35 @@ defmodule Sentry.PlugContext do
is_map(value) ->
scrub_map(value, scrubbed_keys, opts)

is_list(value) ->
scrub_list(value, scrubbed_keys, opts)

true ->
value
end

{key, value}
end)
end

@spec scrub_list(list(), list(String.t()), keyword()) :: list()
defp scrub_list(list, scrubbed_keys, opts) do
Enum.map(list, fn value ->
cond do
is_map(value) && Map.has_key?(value, :__struct__) ->
value
|> Map.from_struct()
|> scrub_map(scrubbed_keys, opts)

is_map(value) ->
scrub_map(value, scrubbed_keys, opts)

is_list(value) ->
scrub_list(value, scrubbed_keys, opts)

true ->
value
end
end)
end
end
10 changes: 8 additions & 2 deletions test/plug_context_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ defmodule Sentry.PlugContextTest do
"count" => 334,
"cc" => "4197-7215-7810-8280",
"another_cc" => "4197721578108280",
"user" => %{"password" => "mypassword"}
"user" => %{"password" => "mypassword"},
"payments" => [
%{"yet_another_cc" => "4197-7215-7810-8280"}
]
})
|> put_req_cookie("secret", "secretvalue")
|> put_req_cookie("regular", "value")
Expand All @@ -101,7 +104,10 @@ defmodule Sentry.PlugContextTest do
"passwd" => "*********",
"password" => "*********",
"secret" => "*********",
"user" => %{"password" => "*********"}
"user" => %{"password" => "*********"},
"payments" => [
%{"yet_another_cc" => "*********"}
]
}
end

Expand Down