Anorov / PySocks

A SOCKS proxy client and wrapper for Python.
Other
1.23k stars 260 forks source link

pysocks is ignoring the relay host provided by the socks proxy #172

Open mvanholsteijn opened 3 days ago

mvanholsteijn commented 3 days ago

We have 3 socks proxies behind a load balancer for HA purposes. It works fine for TCP proxy requests, but fails for UDP proxy request. The socks proxy returns the correct IP address and port for the UDP proxy port, but PySocks overrides the hostname with the hostname of the loadbalancer.

https://github.com/Anorov/PySocks/blob/91dcdf0fec424b6afe9ceef88de63b72d2f8fcfe/socks.py#L355-L358

The comment suggests this is intentional, but the SOCKS5 proxy is allowed to return a different IP address to bind to, so the fix in the client code hides a misconfiguration in the SOCKS proxy.

vadmium commented 2 days ago

That sounds like my fault: commit 2f4fb3bc2fdc. I haven’t used this library for a long time, but I suspect you are right that I was working around a misconfiguration (or misuse?) of a publicly accessible proxy.

Maybe it would be cleaner to undo that commit, or add an option to opt in to the overriding.

mvanholsteijn commented 2 days ago

I was looking at adding it as an option, but i think we would to need extend the set_proxy() method with an extra parameter, which will propagate to set_default_proxy().

I would suggest applying the KISS principle and rollback the commit.