Sensitive data in Phoenix.Socket.Message when genserver exits

Thanks @benwilson512! I was able to add a custom Inspect protocol and just drop the form values if present. Note, I’m not currently checking for the form event type in the payload, but it’d probably be best to do so.

  defimpl Inspect, for: Phoenix.Socket.Message do
    @msg "Form values redacted for security purposes."

    def inspect(%Phoenix.Socket.Message{} = msg, opts) do
      {_, updated} =
        get_and_update_in(msg, [Access.key(:payload, nil), Access.key("value", nil)], fn
          nil -> :pop
          v -> {v, @msg}
        end)

      Inspect.Any.inspect(updated, opts)
    end
  end
8 Likes