Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): name the wwjs proxy when its credentials are malformed
Yudhi Armyndharisc1dc99474f33
diff --git a/src/engine/adapters/wwebjs-proxy.spec.ts b/src/engine/adapters/wwebjs-proxy.spec.tsnew file mode 100644index 000000000..f9b90078c--- /dev/null+++ b/src/engine/adapters/wwebjs-proxy.spec.ts@@ -0,0 +1,17 @@+import { buildProxyLaunchConfig } from './wwebjs-proxy';++describe('buildProxyLaunchConfig credential decoding', () => {+ // A lone `%` used to surface as a bare `URI malformed` that named nothing about the proxy.+ it.each(['http://u:p%zz@proxy:8080', 'socks5://us%er:pass@proxy:1080'])('names the proxy for %s', url => {+ expect(() => buildProxyLaunchConfig(url)).toThrow(+ 'The session proxy URL has malformed percent-encoded credentials',+ );+ });++ it('accepts a correctly escaped literal %', () => {+ expect(buildProxyLaunchConfig('http://u:p%25zz@proxy:8080').proxyAuthentication).toEqual({+ username: 'u',+ password: 'p%zz',+ });+ });+});diff --git a/src/engine/adapters/wwebjs-proxy.ts b/src/engine/adapters/wwebjs-proxy.tsindex 5175bdf88..4b63a6a2a 100644--- a/src/engine/adapters/wwebjs-proxy.ts+++ b/src/engine/adapters/wwebjs-proxy.ts@@ -31,8 +31,15 @@ export interface ProxyLaunchConfig {export function buildProxyLaunchConfig(url: string): ProxyLaunchConfig {const parsed = new URL(url);const serverArg = `${parsed.protocol}//${parsed.host}`;- const username = decodeURIComponent(parsed.username);- const password = decodeURIComponent(parsed.password);+ let username: string;+ let password: string;+ try {+ username = decodeURIComponent(parsed.username);+ password = decodeURIComponent(parsed.password);+ } catch {+ // A lone `%` in a stored URL that bypassed DTO validation; the bare `URI malformed` names nothing.+ throw new Error('The session proxy URL has malformed percent-encoded credentials');+ }const hasCredentials = username !== '' || password !== '';const isSocks = parsed.protocol === 'socks4:' || parsed.protocol === 'socks5:';if (hasCredentials && !isSocks) {