File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ defmodule Sentry.PlugContext do
171171 end
172172
173173 @ doc """
174- Recursively scrubs a map that may have nested maps
174+ Recursively scrubs a map that may have nested maps or lists
175175
176176 Accepts a list of keys to scrub, and a list of options to configure
177177
@@ -206,11 +206,35 @@ defmodule Sentry.PlugContext do
206206 is_map ( value ) ->
207207 scrub_map ( value , scrubbed_keys , opts )
208208
209+ is_list ( value ) ->
210+ scrub_list ( value , scrubbed_keys , opts )
211+
209212 true ->
210213 value
211214 end
212215
213216 { key , value }
214217 end )
215218 end
219+
220+ @ spec scrub_list ( list ( ) , list ( String . t ( ) ) , keyword ( ) ) :: list ( )
221+ defp scrub_list ( list , scrubbed_keys , opts ) do
222+ Enum . map ( list , fn value ->
223+ cond do
224+ is_map ( value ) && Map . has_key? ( value , :__struct__ ) ->
225+ value
226+ |> Map . from_struct ( )
227+ |> scrub_map ( scrubbed_keys , opts )
228+
229+ is_map ( value ) ->
230+ scrub_map ( value , scrubbed_keys , opts )
231+
232+ is_list ( value ) ->
233+ scrub_list ( value , scrubbed_keys , opts )
234+
235+ true ->
236+ value
237+ end
238+ end )
239+ end
216240end
Original file line number Diff line number Diff line change @@ -82,7 +82,10 @@ defmodule Sentry.PlugContextTest do
8282 "count" => 334 ,
8383 "cc" => "4197-7215-7810-8280" ,
8484 "another_cc" => "4197721578108280" ,
85- "user" => % { "password" => "mypassword" }
85+ "user" => % { "password" => "mypassword" } ,
86+ "payments" => [
87+ % { "yet_another_cc" => "4197-7215-7810-8280" }
88+ ]
8689 } )
8790 |> put_req_cookie ( "secret" , "secretvalue" )
8891 |> put_req_cookie ( "regular" , "value" )
@@ -101,7 +104,10 @@ defmodule Sentry.PlugContextTest do
101104 "passwd" => "*********" ,
102105 "password" => "*********" ,
103106 "secret" => "*********" ,
104- "user" => % { "password" => "*********" }
107+ "user" => % { "password" => "*********" } ,
108+ "payments" => [
109+ % { "yet_another_cc" => "*********" }
110+ ]
105111 }
106112 end
107113
You can’t perform that action at this time.
0 commit comments