Skip to content

Add SOCKS5 UDP ASSOCIATE support for upstream proxy chaining #634

@Manouchehri

Description

@Manouchehri

When proxy-chain is configured to chain through an upstream SOCKS5 proxy, we should support forwarding UDP traffic, not just TCP.

The socks npm package we already use (v2.8.3) supports the associate command, but we never use it. In src/chain_socks.ts:85-89:

const client = await SocksClient.createConnection({
    proxy,
    command: 'connect',  // always TCP
    destination,
});

To support UDP through SOCKS5 upstreams:

  • Add a chainSocksUdp() function in src/chain_socks.ts that uses command: 'associate'
  • Handle the BND.ADDR and BND.PORT returned by the upstream SOCKS5 server
  • Create a local UDP socket to relay datagrams to the upstream's relay address
  • Manage the association lifecycle (the TCP control connection must stay open)

The routing logic in src/server.ts would need updating to detect when an incoming request is for UDP and dispatch to the appropriate handler.

This depends on having incoming UDP support first (see related ticket #633), since we need to accept UDP from clients before we can forward it anywhere.

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