Repository navigation
proxy: a SOCKS CONNECT to a mitmProxy host goes through the MITM socket - #764
Merged
Merged
Conversation
The proxy port serves HTTP and SOCKS5. With network.mitmProxy set, an HTTP CONNECT to one of its domains is tunnelled into the MITM proxy's unix socket, but a SOCKS CONNECT to the same host was dialed directly, or through parentProxy, so the MITM proxy never saw it. createSocksProxyServer now takes the same getMitmSocketPath hook as the HTTP proxy, and the manager passes it. For a host the hook covers, the SOCKS tunnel is opened with an HTTP CONNECT into that socket, carrying the canonical host and the requested port. That route comes before parentProxy and the direct dial, and nothing else is tried when it fails: the client gets "host unreachable". The allow and deny rules and refuseOpaqueTunnels are applied first, as before.
ig-ant
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The proxy port speaks both HTTP and SOCKS5. With
network.mitmProxyconfigured, an HTTP CONNECT to one of its domains is tunnelled into the MITM proxy's unix socket, but a SOCKS5 CONNECT to the same host was dialed directly (or throughparentProxy), so the MITM proxy never saw that connection.What this changes
createSocksProxyServertakes an optionalgetMitmSocketPath(host), the hookcreateHttpProxyServeralready has, andSandboxManagerpasses the same function to both servers.openConnectTunnelinto the unix socket: an HTTP CONNECT carrying the canonical host and the requested port, the same callhttp-proxy.tsmakes for a CONNECT.inet_atonspellings of a MITM host all take the MITM route.What does not change: the allow and deny rules still run first (in the ruleset validator), so no host outside the allow rules becomes reachable.
refuseOpaqueTunnelsstill refuses every SOCKS CONNECT before any of this runs. Hosts outsidemitmProxy.domainstake the routes they took before.The resolved-address check is not applied on the MITM route, as on the HTTP leg. That covers its built-in set (loopback, link-local, this host's addresses, cloud metadata) as well as
deniedResolvedAddresses. The README's "Resolved-address check" section already says so formitmProxy: that hop resolves the name and owns its own address policy.No README or schema text needed editing: neither describes
mitmProxyas HTTP-only, and the schema's "Routes matching domains through an upstream proxy via Unix socket" is now true of both legs.Behaviour change for existing users
Only configurations that set
network.mitmProxyare affected. For those, a SOCKS connection to amitmProxy.domainshost now arrives at the MITM socket asCONNECT host:port:mitmProxyname that resolved into the denied address set was refused by the library. Now that connection goes to the MITM proxy, which makes that call.Alternative not taken
Refuse SOCKS CONNECTs to
mitmProxy.domainshosts instead of routing them. That is a few lines smaller, but it breaks any client that can only speak SOCKS to those hosts, and it makes the two legs of one port behave differently. Routing mirrors the HTTP leg and keeps those clients working.