Skip to content

Please honor HTTP header "X-Real-IP" when it exists #5

@pini-gh

Description

@pini-gh

HI,

My tmate instance sits behind an Nginx reverse proxy, and tmate-websocket reports the proxy's IP address instead of the client's.

I can't use proxy protocol, but the HTTP header X-Real-IP is set. It would be great if tmate-websocket could use it when available.

Looking at the code, it might be just a one line addition iinto lib/tmate/ws_api/websocket.ex:

diff --git a/lib/tmate/ws_api/websocket.ex b/lib/tmate/ws_api/websocket.ex
index 2d667fd..f502091 100644
--- a/lib/tmate/ws_api/websocket.ex
+++ b/lib/tmate/ws_api/websocket.ex
@@ -26,6 +26,7 @@ defmodule Tmate.WsApi.WebSocket do
               :ok ->
                 ip = case req do
                   %{proxy_header: %{src_address: ip}} -> ip
+                  %{headers: %{"x-real-ip" => ip}} -> ip
                   %{peer: {ip, _port}} -> ip
                 end
                 ip = :inet_parse.ntoa(ip) |> to_string

Please bear with me as I don't know Elixir, Phoenix, cowboy et al. I spent some time digging into the source code and reading documentation, but this patch proposal is just a wild guess. I don't even know how to build the app.

Anyway. In case this is something as simple as that, this fix would be very much appreciated.

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions