feat(whatsapp): proxy support for the Baileys bridge - #12787
Closed
d0uub wants to merge 1 commit into
Closed
Conversation
Adds optional outbound HTTP/HTTPS proxy support to the WhatsApp
bridge so users behind a corporate proxy can still establish the
WebSocket and HTTP traffic Baileys needs.
Behaviour:
- If WHATSAPP_PROXY (preferred) or HTTPS_PROXY / HTTP_PROXY is
set in the environment, the bridge:
* routes the makeWASocket WebSocket through HttpsProxyAgent
(passed as 'agent')
* routes Baileys' fetch-based traffic through the same proxy
via 'fetchAgent' and undici's setGlobalDispatcher.
- If no proxy env var is set, behaviour is unchanged from upstream.
- Proxy URL is logged with the password masked (//user:***@).
- fetchLatestBaileysVersion() is wrapped in try/catch with a
hard-coded fallback version, since that endpoint is frequently
blocked by corporate proxies and would otherwise abort startup.
Dependencies added:
- https-proxy-agent ^7.0.5 (WebSocket proxy)
- undici ^6.21.0 (fetch dispatcher)
Both are imported lazily so they're only loaded when a proxy URL
is configured.
d0uub
force-pushed
the
feat/whatsapp-proxy
branch
from
May 29, 2026 12:55
d57c069 to
fca7268
Compare
This was referenced Jun 10, 2026
teknium1
reviewed
Jul 12, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for addressing a real current-main gap: scripts/whatsapp-bridge/bridge.js:389-408 still fetches the Baileys version and opens makeWASocket() without proxy options.
Problems
scripts/whatsapp-bridge/bridge.js:55in this PR logs rawPROXY_URLwhen lazy imports fail. A proxy URL may containuser:password@host; use the masked value in this error path too.- The change has no proxy regression test. The existing bridge test files cover unrelated helpers and do not exercise proxy resolution or socket options.
Suggested changes
- Redact the URL consistently in every log path, including the import-error handler.
- Add a focused Node test for precedence, masked logging, and generated Baileys options.
- Please align the egress direction with maintainers before salvage: linked open PR #21627 proposes direct bridge egress, while this PR enables proxy egress.
Automated hermes-sweeper review.
| console.log('[bridge] Proxy enabled:', _masked); | ||
| } catch (e) { | ||
| console.error('[bridge] Failed to enable proxy (' + PROXY_URL + '):', e.message); | ||
| console.error('[bridge] Run: npm install https-proxy-agent undici'); |
Contributor
There was a problem hiding this comment.
This error path logs the raw PROXY_URL, unlike the masked success log above. An import failure would therefore expose an embedded proxy password in bridge logs; log the masked value here as well.
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.
Adds optional outbound HTTP/HTTPS proxy support to the WhatsApp bridge so users behind a corporate proxy can still establish the WebSocket and HTTP traffic Baileys needs.
Behaviour:
WHATSAPP_PROXY(preferred) orHTTPS_PROXY/HTTP_PROXYis set in the environment, the bridge:makeWASocketWebSocket throughHttpsProxyAgent(passed asagent)fetchAgentand undici'ssetGlobalDispatcher.//user:***@).fetchLatestBaileysVersion()is wrapped in try/catch with a hard-coded fallback version, since that endpoint is frequently blocked by corporate proxies and would otherwise abort startup.Dependencies added:
https-proxy-agent ^7.0.5(WebSocket proxy)undici ^6.21.0(fetch dispatcher)Both are imported lazily so they're only loaded when a proxy URL is configured.
What does this PR do?
The Baileys-based WhatsApp bridge currently has no way to honour an outbound HTTP/HTTPS proxy, which means it cannot connect from any environment that forces all egress through one (corporate networks, locked-down VMs, some cloud egress policies, etc.). This PR makes the bridge proxy-aware in a fully opt-in way: if
WHATSAPP_PROXY/HTTPS_PROXY/HTTP_PROXYis present, the WebSocket and Baileys' internalfetchtraffic both route through it; otherwise behaviour is byte-for-byte identical to before.The implementation uses the two community-standard libraries for this —
https-proxy-agentfor the underlying socket andundici'sProxyAgentfor fetch — both lazy-imported so users without a proxy never load them. It also defends against a related failure mode:fetchLatestBaileysVersion()is the very first network call the bridge makes and is frequently blocked by the same proxies, so it's now wrapped in try/catch with a known-good fallback version, preventing the bridge from failing to even start.Related Issue
Fixes # (no existing issue — happy to file one if maintainers prefer)
Type of Change
Changes Made
scripts/whatsapp-bridge/bridge.js— added a proxy-detection block at the top of the file that readsWHATSAPP_PROXY/HTTPS_PROXY/HTTP_PROXY, dynamically importshttps-proxy-agentandundici, callssetGlobalDispatcher(new ProxyAgent(PROXY_URL)), and exposes the constructedagentformakeWASocket. Also wrappedfetchLatestBaileysVersion()in try/catch with a hard-coded fallback version[2, 3000, 1023223821]so a blocked version-fetch no longer kills startup. The proxy URL is masked (//user:***@) before being logged.scripts/whatsapp-bridge/package.json— addedhttps-proxy-agent ^7.0.5andundici ^6.21.0todependencies.scripts/whatsapp-bridge/package-lock.json— regenerated to include the new transitive deps.How to Test
Without a proxy (regression check — should be identical to upstream):
cd scripts/whatsapp-bridge && npm installnode bridge.js— bridge starts, scans QR, connects normally. No[bridge] using proxyline appears in the log.With a proxy:
cd scripts/whatsapp-bridge && npm installWHATSAPP_PROXY=http://user:pass@proxy.corp.example:8080 node bridge.js(or useHTTPS_PROXY=…for the same effect).[bridge] using proxy http://user:***@proxy.corp.example:8080(password masked).wss://socket and Baileys'fetchcalls (e.g. profile pic uploads) flow through the proxy.web.whatsapp.com/check-updateto confirm thefetchLatestBaileysVersionfallback kicks in ([bridge] fetchLatestBaileysVersion failed, using fallback).Checklist
Code
feat(whatsapp): …)pytest tests/ -qand all tests pass — N/A: this PR only touches the Node.js bridge, no Python code changedDocumentation & Housekeeping
docs/, docstrings) — can add a short note indocs/platforms/whatsapp.mdif requestedcli-config.yaml.exampleif I added/changed config keys — N/A (purely env-var driven, no config schema change)CONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AScreenshots / Logs