fix(proxy): preserve SOCKS5 remote DNS semantics#1369
Open
maybeknott wants to merge 1 commit into
Open
Conversation
SOCKS5 clients can send domain-name targets with ATYP=0x03, which gives the proxy an unresolved hostname and lets resolution happen on a remote transport path. If that flow later falls through to raw TCP direct passthrough, TcpStream::connect((host, port)) asks the local resolver for the destination address and can expose the target hostname outside the tunnel. The SOCKS5 request handler now marks ATYP=domain flows as requiring remote DNS preservation before handing the stream to the shared tunnel dispatcher. HTTP CONNECT and plain HTTP proxy requests pass the flag disabled, so this guard is tied to SOCKS5 domain-name semantics rather than changing every proxy mode. Raw TCP passthrough now refuses direct hostname fallback when remote DNS is required and no upstream SOCKS5 proxy is available. If an upstream SOCKS5 proxy is configured, the hostname is sent to that proxy unchanged so resolution can remain remote. If the upstream SOCKS5 connection fails for a hostname that requires remote DNS, the proxy returns without falling back to direct local resolution. IP literals remain eligible for direct passthrough because they do not require DNS resolution. Full Tunnel, Apps Script HTTP relay, MITM relay, and SNI-rewrite paths continue to receive the original hostname without introducing local destination lookups. The guide documents the fail-closed behavior for SOCKS5 domain targets, and unit coverage exercises hostname refusal, IPv4 and IPv6 literal allowance, upstream SOCKS5 allowance, and non-SOCKS call-site behavior.
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.
SOCKS5 clients can send domain-name targets with ATYP=0x03, which gives the proxy an unresolved hostname and lets resolution happen on a remote transport path. If that flow later falls through to raw TCP direct passthrough, TcpStream::connect((host, port)) asks the local resolver for the destination address and can expose the target hostname outside the tunnel.
The SOCKS5 request handler now marks ATYP=domain flows as requiring remote DNS preservation before handing the stream to the shared tunnel dispatcher. HTTP CONNECT and plain HTTP proxy requests pass the flag disabled, so this guard is tied to SOCKS5 domain-name semantics rather than changing every proxy mode.
Raw TCP passthrough now refuses direct hostname fallback when remote DNS is required and no upstream SOCKS5 proxy is available. If an upstream SOCKS5 proxy is configured, the hostname is sent to that proxy unchanged so resolution can remain remote. If the upstream SOCKS5 connection fails for a hostname that requires remote DNS, the proxy returns without falling back to direct local resolution.
IP literals remain eligible for direct passthrough because they do not require DNS resolution. Full Tunnel, Apps Script HTTP relay, MITM relay, and SNI-rewrite paths continue to receive the original hostname without introducing local destination lookups.
The guide documents the fail-closed behavior for SOCKS5 domain targets, and unit coverage exercises hostname refusal, IPv4 and IPv6 literal allowance, upstream SOCKS5 allowance, and non-SOCKS call-site behavior.