From 3b139078c3ed8ce9b1e708ce9805dc4a31e3628c Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Wed, 19 Nov 2025 13:34:33 -0300 Subject: [PATCH 1/9] Removendo uso do undici com proxy socks --- src/utils/makeProxyAgent.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index e882876e..3de058cd 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -19,11 +19,13 @@ function selectProxyAgent(proxyUrl: string): HttpsProxyAgent | SocksProx // the end so, we add the protocol constants without the `:` to avoid confusion. const PROXY_HTTP_PROTOCOL = 'http:'; const PROXY_SOCKS_PROTOCOL = 'socks:'; + const PROXY_SOCKS5_PROTOCOL = 'socks5:'; switch (url.protocol) { case PROXY_HTTP_PROTOCOL: return new HttpsProxyAgent(url); case PROXY_SOCKS_PROTOCOL: + case PROXY_SOCKS5_PROTOCOL: return new SocksProxyAgent(url); default: throw new Error(`Unsupported proxy protocol: ${url.protocol}`); @@ -45,7 +47,7 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent | return selectProxyAgent(proxyUrl); } -export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent { +export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent|SocksProxyAgent { let proxyUrl: string let protocol: string @@ -73,10 +75,10 @@ export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent { switch (protocol) { case PROXY_HTTP_PROTOCOL: case PROXY_HTTPS_PROTOCOL: + return new ProxyAgent(proxyUrl) case PROXY_SOCKS4_PROTOCOL: case PROXY_SOCKS5_PROTOCOL: - return new ProxyAgent(proxyUrl) - + return new SocksProxyAgent(proxyUrl) default: throw new Error(`Unsupported proxy protocol: ${protocol}`) } From 31a6f2d92e6cb5eea5ea360b96c7d8dd1cb769ac Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Wed, 19 Nov 2025 14:00:17 -0300 Subject: [PATCH 2/9] ; --- src/utils/makeProxyAgent.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index 3de058cd..ae15bb05 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -48,38 +48,38 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent | } export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent|SocksProxyAgent { - let proxyUrl: string - let protocol: string + let proxyUrl: string; + let protocol: string; if (typeof proxy === 'string') { - const url = new URL(proxy) - protocol = url.protocol.replace(':', '') - proxyUrl = proxy + const url = new URL(proxy); + protocol = url.protocol.replace(':', ''); + proxyUrl = proxy; } else { - const { host, password, port, protocol: proto, username } = proxy - protocol = (proto || 'http').replace(':', '') + const { host, password, port, protocol: proto, username } = proxy; + protocol = (proto || 'http').replace(':', ''); if (protocol === 'socks') { - protocol = 'socks5' + protocol = 'socks5'; } - const auth = username && password ? `${username}:${password}@` : '' - proxyUrl = `${protocol}://${auth}${host}:${port}` + const auth = username && password ? `${username}:${password}@` : ''; + proxyUrl = `${protocol}://${auth}${host}:${port}`; } - - const PROXY_HTTP_PROTOCOL = 'http' - const PROXY_HTTPS_PROTOCOL = 'https' - const PROXY_SOCKS4_PROTOCOL = 'socks4' - const PROXY_SOCKS5_PROTOCOL = 'socks5' +; + const PROXY_HTTP_PROTOCOL = 'http'; + const PROXY_HTTPS_PROTOCOL = 'https'; + const PROXY_SOCKS4_PROTOCOL = 'socks4'; + const PROXY_SOCKS5_PROTOCOL = 'socks5'; switch (protocol) { case PROXY_HTTP_PROTOCOL: case PROXY_HTTPS_PROTOCOL: - return new ProxyAgent(proxyUrl) + return new ProxyAgent(proxyUrl); case PROXY_SOCKS4_PROTOCOL: case PROXY_SOCKS5_PROTOCOL: - return new SocksProxyAgent(proxyUrl) + return new SocksProxyAgent(proxyUrl); default: - throw new Error(`Unsupported proxy protocol: ${protocol}`) + throw new Error(`Unsupported proxy protocol: ${protocol}`); } } From 179af3f41c3859df20ad0c4604ffbd60414b75c6 Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Wed, 19 Nov 2025 14:02:52 -0300 Subject: [PATCH 3/9] lint --- src/utils/makeProxyAgent.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index ae15bb05..e84f79e8 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -1,8 +1,7 @@ +import { ProxyAgent } from 'undici'; import { HttpsProxyAgent } from 'https-proxy-agent'; import { SocksProxyAgent } from 'socks-proxy-agent'; -import { ProxyAgent } from 'undici' - type Proxy = { host: string; password?: string; @@ -47,7 +46,7 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent | return selectProxyAgent(proxyUrl); } -export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent|SocksProxyAgent { +export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent | SocksProxyAgent { let proxyUrl: string; let protocol: string; @@ -65,8 +64,8 @@ export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent|SocksPro const auth = username && password ? `${username}:${password}@` : ''; proxyUrl = `${protocol}://${auth}${host}:${port}`; - } -; + }; + const PROXY_HTTP_PROTOCOL = 'http'; const PROXY_HTTPS_PROTOCOL = 'https'; const PROXY_SOCKS4_PROTOCOL = 'socks4'; From 067f0999b55de493e227fcf9491f68c8b238d24a Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Wed, 19 Nov 2025 14:07:23 -0300 Subject: [PATCH 4/9] lint --- .../integrations/channel/whatsapp/whatsapp.baileys.service.ts | 2 +- src/utils/makeProxyAgent.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 2636adbd..937841cd 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -82,7 +82,7 @@ import { createId as cuid } from '@paralleldrive/cuid2'; import { Instance, Message } from '@prisma/client'; import { createJid } from '@utils/createJid'; import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion'; -import {makeProxyAgent, makeProxyAgentUndici} from '@utils/makeProxyAgent'; +import { makeProxyAgent, makeProxyAgentUndici } from '@utils/makeProxyAgent'; import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache'; import { status } from '@utils/renderStatus'; import { sendTelemetry } from '@utils/sendTelemetry'; diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index e84f79e8..4f555c19 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -64,7 +64,7 @@ export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent | SocksP const auth = username && password ? `${username}:${password}@` : ''; proxyUrl = `${protocol}://${auth}${host}:${port}`; - }; + } const PROXY_HTTP_PROTOCOL = 'http'; const PROXY_HTTPS_PROTOCOL = 'https'; @@ -81,4 +81,4 @@ export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent | SocksP default: throw new Error(`Unsupported proxy protocol: ${protocol}`); } -} +} \ No newline at end of file From d3e3c458a0d6b30b2977d00938c79643f18adf93 Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Wed, 19 Nov 2025 14:09:07 -0300 Subject: [PATCH 5/9] lint --- src/utils/makeProxyAgent.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index 4f555c19..c2848292 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -1,6 +1,6 @@ -import { ProxyAgent } from 'undici'; import { HttpsProxyAgent } from 'https-proxy-agent'; import { SocksProxyAgent } from 'socks-proxy-agent'; +import { ProxyAgent } from 'undici'; type Proxy = { host: string; @@ -81,4 +81,4 @@ export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent | SocksP default: throw new Error(`Unsupported proxy protocol: ${protocol}`); } -} \ No newline at end of file +} From ea88edd512204c6a3722998ed64eead967b59ccc Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Wed, 19 Nov 2025 16:51:59 -0300 Subject: [PATCH 6/9] socks --- package-lock.json | 11 +++++++++++ package.json | 1 + src/utils/makeProxyAgent.ts | 31 ++++++++++++++++++++++++------- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index c1c6d180..a4481cdc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "eventemitter2": "^6.4.9", "express": "^4.21.2", "express-async-errors": "^3.1.1", + "fetch-socks": "^1.3.2", "fluent-ffmpeg": "^2.1.3", "form-data": "^4.0.1", "https-proxy-agent": "^7.0.6", @@ -8628,6 +8629,16 @@ "reusify": "^1.0.4" } }, + "node_modules/fetch-socks": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/fetch-socks/-/fetch-socks-1.3.2.tgz", + "integrity": "sha512-vkH5+Zgj2yEbU57Cei0iyLgTZ4OkEKJj56Xu3ViB5dpsl599JgEooQ3x6NVagIFRHWnWJ+7K0MO0aIV1TMgvnw==", + "license": "MIT", + "dependencies": { + "socks": "^2.8.2", + "undici": ">=6" + } + }, "node_modules/fflate": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz", diff --git a/package.json b/package.json index aa7e508f..2e1f239c 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "fluent-ffmpeg": "^2.1.3", "form-data": "^4.0.1", "https-proxy-agent": "^7.0.6", + "fetch-socks": "^1.3.2", "i18next": "^23.7.19", "jimp": "^1.6.0", "json-schema": "^0.4.0", diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index c2848292..c2f5affa 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -1,3 +1,4 @@ +import { socksDispatcher } from 'fetch-socks'; import { HttpsProxyAgent } from 'https-proxy-agent'; import { SocksProxyAgent } from 'socks-proxy-agent'; import { ProxyAgent } from 'undici'; @@ -46,7 +47,7 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent | return selectProxyAgent(proxyUrl); } -export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent | SocksProxyAgent { +export function makeProxyAgentUndici(proxy: Proxy | string) { let proxyUrl: string; let protocol: string; @@ -57,15 +58,15 @@ export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent | SocksP } else { const { host, password, port, protocol: proto, username } = proxy; protocol = (proto || 'http').replace(':', ''); - - if (protocol === 'socks') { - protocol = 'socks5'; - } + if (protocol === 'socks') protocol = 'socks5'; const auth = username && password ? `${username}:${password}@` : ''; proxyUrl = `${protocol}://${auth}${host}:${port}`; } + // Normalização + protocol = protocol.toLowerCase(); + const PROXY_HTTP_PROTOCOL = 'http'; const PROXY_HTTPS_PROTOCOL = 'https'; const PROXY_SOCKS4_PROTOCOL = 'socks4'; @@ -74,10 +75,26 @@ export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent | SocksP switch (protocol) { case PROXY_HTTP_PROTOCOL: case PROXY_HTTPS_PROTOCOL: + // Proxy HTTP/HTTPS → usar ProxyAgent do Undici return new ProxyAgent(proxyUrl); + case PROXY_SOCKS4_PROTOCOL: - case PROXY_SOCKS5_PROTOCOL: - return new SocksProxyAgent(proxyUrl); + case PROXY_SOCKS5_PROTOCOL: { + let type: 4 | 5 = 5; + + if (PROXY_SOCKS4_PROTOCOL === protocol) type = 4; + + const url = new URL(proxyUrl); + + return socksDispatcher({ + type: type, + host: url.hostname, + port: Number(url.port), + userId: url.username || undefined, + password: url.password || undefined, + }); + } + default: throw new Error(`Unsupported proxy protocol: ${protocol}`); } From af47b859e41be51732768cf7f1334b10a277b357 Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Mon, 24 Nov 2025 13:59:50 -0300 Subject: [PATCH 7/9] socks5 update --- src/utils/makeProxyAgent.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index c2f5affa..5be908f0 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -1,7 +1,7 @@ import { socksDispatcher } from 'fetch-socks'; import { HttpsProxyAgent } from 'https-proxy-agent'; import { SocksProxyAgent } from 'socks-proxy-agent'; -import { ProxyAgent } from 'undici'; +import { Agent, ProxyAgent } from 'undici'; type Proxy = { host: string; @@ -26,7 +26,16 @@ function selectProxyAgent(proxyUrl: string): HttpsProxyAgent | SocksProx return new HttpsProxyAgent(url); case PROXY_SOCKS_PROTOCOL: case PROXY_SOCKS5_PROTOCOL: - return new SocksProxyAgent(url); + + let urlSocks = ''; + + if(url.username && url.password) { + urlSocks = `socks://${url.username}:${url.password}@${url.hostname}:${url.port}`; + } else { + urlSocks = `socks://${url.hostname}:${url.port}`; + } + + return new SocksProxyAgent(urlSocks); default: throw new Error(`Unsupported proxy protocol: ${url.protocol}`); } From 879bee962b91a460800dd59b2208215925753c7a Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Mon, 24 Nov 2025 14:17:27 -0300 Subject: [PATCH 8/9] lint --- src/utils/makeProxyAgent.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index 5be908f0..03cc58cf 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -1,7 +1,7 @@ import { socksDispatcher } from 'fetch-socks'; import { HttpsProxyAgent } from 'https-proxy-agent'; import { SocksProxyAgent } from 'socks-proxy-agent'; -import { Agent, ProxyAgent } from 'undici'; +import { ProxyAgent } from 'undici'; type Proxy = { host: string; @@ -25,8 +25,7 @@ function selectProxyAgent(proxyUrl: string): HttpsProxyAgent | SocksProx case PROXY_HTTP_PROTOCOL: return new HttpsProxyAgent(url); case PROXY_SOCKS_PROTOCOL: - case PROXY_SOCKS5_PROTOCOL: - + case PROXY_SOCKS5_PROTOCOL: { let urlSocks = ''; if(url.username && url.password) { @@ -36,6 +35,7 @@ function selectProxyAgent(proxyUrl: string): HttpsProxyAgent | SocksProx } return new SocksProxyAgent(urlSocks); + } default: throw new Error(`Unsupported proxy protocol: ${url.protocol}`); } @@ -73,7 +73,6 @@ export function makeProxyAgentUndici(proxy: Proxy | string) { proxyUrl = `${protocol}://${auth}${host}:${port}`; } - // Normalização protocol = protocol.toLowerCase(); const PROXY_HTTP_PROTOCOL = 'http'; @@ -84,7 +83,6 @@ export function makeProxyAgentUndici(proxy: Proxy | string) { switch (protocol) { case PROXY_HTTP_PROTOCOL: case PROXY_HTTPS_PROTOCOL: - // Proxy HTTP/HTTPS → usar ProxyAgent do Undici return new ProxyAgent(proxyUrl); case PROXY_SOCKS4_PROTOCOL: From 5c58cb7eaecebbe9b025e65e75fc92aea367b22f Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Mon, 24 Nov 2025 14:19:48 -0300 Subject: [PATCH 9/9] lint --- src/utils/makeProxyAgent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index 03cc58cf..989fc95e 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -28,7 +28,7 @@ function selectProxyAgent(proxyUrl: string): HttpsProxyAgent | SocksProx case PROXY_SOCKS5_PROTOCOL: { let urlSocks = ''; - if(url.username && url.password) { + if (url.username && url.password) { urlSocks = `socks://${url.username}:${url.password}@${url.hostname}:${url.port}`; } else { urlSocks = `socks://${url.hostname}:${url.port}`;