Skip to content

Commit 9f93250

Browse files
florishwhatyouhide
authored andcommitted
Use deeply nested param filtering (#116)
This ensures nested params are also filtered (not only top-level). Inspired by https://github.com/phoenixframework/phoenix/blob/e4d795ecd3fbf6d28e58f0d4ff678a8288b1a130/lib/phoenix/logger.ex#L77
1 parent e23b003 commit 9f93250

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

pages/Using Rollbax in Plug-based applications.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,28 @@ defp handle_errors(conn, error) do
6969
|> Plug.Conn.fetch_cookies()
7070
|> Plug.Conn.fetch_query_params()
7171

72-
params =
73-
for {key, _value} = tuple <- conn.params, into: %{} do
74-
if key in ["password", "password_confirmation"] do
75-
{key, "[FILTERED]"}
76-
else
77-
tuple
78-
end
79-
end
72+
params = normalize_params(conn.params)
8073

8174
# Same as the examples above
8275
end
76+
77+
defp normalize_params(%Plug.Conn.Unfetched{aspect: :params}) do
78+
"unfetched"
79+
end
80+
81+
defp normalize_params(%{} = map) do
82+
Enum.into(map, %{}, fn {k, v} ->
83+
if is_binary(k) and String.contains?(k, ["password"]) do
84+
{k, "[FILTERED]"}
85+
else
86+
{k, normalize_params(v)}
87+
end
88+
end)
89+
end
90+
91+
defp normalize_params([_ | _] = list) do
92+
Enum.map(list, &normalize_params/1)
93+
end
94+
95+
defp normalize_params(other), do: other
8396
```

0 commit comments

Comments
 (0)