Skip to content

Commit ee7d131

Browse files
solnicclaude
andcommitted
refactor(plug_context): delegate default scrubbers to Sentry.Scrubber
Removes the duplicated denylist constants, placeholder, credit-card regex, and recursive scrub_map/scrub_list helpers from Sentry.PlugContext in favor of the shared Sentry.Scrubber module. Public function signatures and the documented default key sets are unchanged. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent ecabb13 commit ee7d131

1 file changed

Lines changed: 4 additions & 34 deletions

File tree

lib/sentry/plug_context.ex

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,8 @@ defmodule Sentry.PlugContext do
153153
end
154154
end
155155

156-
@default_scrubbed_param_keys ["password", "passwd", "secret"]
157-
@default_scrubbed_header_keys ["authorization", "authentication", "cookie"]
158-
@scrubbed_value "*********"
156+
@default_scrubbed_param_keys Sentry.Scrubber.default_param_keys()
157+
@default_scrubbed_header_keys Sentry.Scrubber.default_header_keys()
159158
@default_plug_request_id_header "x-request-id"
160159

161160
@doc false
@@ -256,7 +255,7 @@ defmodule Sentry.PlugContext do
256255
def default_header_scrubber(conn) do
257256
conn.req_headers
258257
|> Map.new()
259-
|> Map.drop(@default_scrubbed_header_keys)
258+
|> Sentry.Scrubber.drop_keys()
260259
end
261260

262261
@doc """
@@ -268,35 +267,6 @@ defmodule Sentry.PlugContext do
268267
"""
269268
@spec default_body_scrubber(Plug.Conn.t()) :: map()
270269
def default_body_scrubber(conn) do
271-
scrub_map(conn.params, @default_scrubbed_param_keys)
270+
Sentry.Scrubber.scrub_map(conn.params)
272271
end
273-
274-
defp scrub_map(map, scrubbed_keys) do
275-
Map.new(map, fn {key, value} ->
276-
value =
277-
cond do
278-
key in scrubbed_keys -> @scrubbed_value
279-
is_binary(value) and value =~ credit_card_regex() -> @scrubbed_value
280-
is_struct(value) -> value |> Map.from_struct() |> scrub_map(scrubbed_keys)
281-
is_map(value) -> scrub_map(value, scrubbed_keys)
282-
is_list(value) -> scrub_list(value, scrubbed_keys)
283-
true -> value
284-
end
285-
286-
{key, value}
287-
end)
288-
end
289-
290-
defp scrub_list(list, scrubbed_keys) do
291-
Enum.map(list, fn value ->
292-
cond do
293-
is_struct(value) -> value |> Map.from_struct() |> scrub_map(scrubbed_keys)
294-
is_map(value) -> scrub_map(value, scrubbed_keys)
295-
is_list(value) -> scrub_list(value, scrubbed_keys)
296-
true -> value
297-
end
298-
end)
299-
end
300-
301-
defp credit_card_regex, do: ~r/^(?:\d[ -]*?){13,16}$/
302272
end

0 commit comments

Comments
 (0)