Skip to content
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
7 changes: 5 additions & 2 deletions lib/error_tracker/integrations/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ defmodule ErrorTracker.Integrations.Plug do
conn |> build_context() |> ErrorTracker.set_context()
end

@sensitive_headers ["cookie", "authorization"]
@sensitive_headers ~w[authorization cookie set-cookie]

defp build_context(%Plug.Conn{} = conn) do
%{
Expand All @@ -120,7 +120,10 @@ defmodule ErrorTracker.Integrations.Plug do
"request.query" => conn.query_string,
"request.method" => conn.method,
"request.ip" => remote_ip(conn),
"request.headers" => conn.req_headers |> Map.new() |> Map.drop(@sensitive_headers),
"request.headers" =>
Map.new(conn.req_headers, fn {header, value} ->
if header in @sensitive_headers, do: {header, "[REDACTED]"}, else: {header, value}
end),
# Depending on the error source, the request params may have not been fetched yet
"request.params" => if(!is_struct(conn.params, Plug.Conn.Unfetched), do: conn.params)
}
Expand Down
9 changes: 3 additions & 6 deletions test/integrations/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ defmodule ErrorTracker.Integrations.PlugTest do

[occurrence] = repo().all(ErrorTracker.Occurrence)

header_names = occurrence.context |> Map.get("request.headers") |> Map.keys()

refute "cookie" in header_names
refute "authorization" in header_names

assert "safe" in header_names
assert occurrence.context["request.headers"]["cookie"] == "[REDACTED]"
assert occurrence.context["request.headers"]["authorization"] == "[REDACTED]"
assert occurrence.context["request.headers"]["safe"] != "[REDACTED]"
end
end
Loading