undici icon indicating copy to clipboard operation
undici copied to clipboard

ProxyAgent: support socks5 protocol

Open idranme opened this issue 1 year ago • 10 comments

This would solve...

Using the socks5 proxy.

The implementation should look like...

import { ProxyAgent } from 'undici'
const client = new ProxyAgent('socks5://127.0.0.1:7890/')

I have also considered...

Additional context

idranme avatar Aug 24 '23 12:08 idranme

This would be amazing, but it'd also be somewhat feasible to create it outside of this module. I recommend that route at this point as we are stretched really thin.

mcollina avatar Aug 24 '23 16:08 mcollina

It would be best if it could be integrated in this module.

idranme avatar Aug 24 '23 16:08 idranme

PRs are welcomed.

mcollina avatar Aug 24 '23 21:08 mcollina

have you tried https://github.com/Kaciras/fetch-socks?

KhafraDev avatar Aug 25 '23 05:08 KhafraDev

have you tried https://github.com/Kaciras/fetch-socks?

https://github.com/Kaciras/fetch-socks/blob/master/package.json#L34

This package depends on an undici. So I don't think it's ideal.

idranme avatar Aug 25 '23 07:08 idranme

the caret means it supports undici versions of at least 5.22.1

KhafraDev avatar Aug 25 '23 18:08 KhafraDev

the caret means it supports undici versions of at least 5.22.1

When I use undici, it installs one more on its side, which will now will exist two undici.

idranme avatar Aug 26 '23 00:08 idranme

you can probably use dedupe

KhafraDev avatar Sep 05 '23 17:09 KhafraDev

Wouldn't it be simpler to make a buildConnector for each type of proxy and use it as a connector?

const httpProxyBuildConnector = (proxy) => {
 return (opts) => {
    const socket = createConnection(opts);
    return socket;
  }
}

const socksProxyBuildConnector = (proxy) => {
  return (opts) => {
    const socket = createConnection(opts);
    return socket;
  }
}

const proxyConnector = httpProxyBuildConnector(proxy);
const proxyAgent = new Agent({connect: proxyConnector });

const resp = await fetch('localhost:3000/', {
  dispatcher: proxyAgent
});

Or you can do it the same way as done by aiohttp in python (https://github.com/Slzdude/aiohttp-proxy)

PandaWorker avatar Sep 09 '23 15:09 PandaWorker

Also after implementation SOCKS5 - we have got CRITICAL Vulnerability ❌ CVE-2023-38545 which affected on the security.

eugenepugach avatar Nov 09 '23 10:11 eugenepugach