-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please honor HTTP header "X-Real-IP" when it exists #5
Comments
I've successfully tested this patch: diff --git a/lib/tmate/ws_api/websocket.ex b/lib/tmate/ws_api/websocket.ex
index 2d667fd..2673f5d 100644
--- a/lib/tmate/ws_api/websocket.ex
+++ b/lib/tmate/ws_api/websocket.ex
@@ -26,6 +26,9 @@ defmodule Tmate.WsApi.WebSocket do
:ok ->
ip = case req do
%{proxy_header: %{src_address: ip}} -> ip
+ %{headers: %{"x-real-ip" => ipstring}} ->
+ {_, ip} = :inet.parse_address(ipstring |> to_charlist)
+ ip
%{peer: {ip, _port}} -> ip
end
ip = :inet_parse.ntoa(ip) |> to_string
Not sure this is the best way of doing it, but it works for me. Would you consider such a PR? |
pini-gh
added a commit
to pini-gh/tmate-websocket
that referenced
this issue
Nov 7, 2021
And because X-Real-IP can be spoofed, gate this feature with TRUST_X_REAL_IP environment variable. Fix tmate-io#5.
pini-gh
added a commit
to pini-gh/tmate-websocket
that referenced
this issue
Jan 22, 2023
And because X-Real-IP can be spoofed, gate this feature with TRUST_X_REAL_IP environment variable. Fix tmate-io#5.
pini-gh
added a commit
to pini-gh/tmate-websocket
that referenced
this issue
Jan 22, 2023
And because X-Real-IP can be spoofed, gate this feature with TRUST_X_REAL_IP environment variable. Fix tmate-io#5.
pini-gh
added a commit
to pini-gh/tmate-websocket
that referenced
this issue
Jan 22, 2023
And because X-Real-IP can be spoofed, gate this feature with TRUST_X_REAL_IP environment variable. Fix tmate-io#5.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 iftmate-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
: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.
The text was updated successfully, but these errors were encountered: