fix(webhook-server): default-bind to loopback instead of 0.0.0.0#2547
Closed
smith-vosburg wants to merge 1 commit into
Closed
fix(webhook-server): default-bind to loopback instead of 0.0.0.0#2547smith-vosburg wants to merge 1 commit into
smith-vosburg wants to merge 1 commit into
Conversation
Extract resolveListenConfig() so the bind address is environment-driven and unit-testable. Default to 127.0.0.1 so the webhook port is not exposed to the LAN; set WEBHOOK_BIND=0.0.0.0 (or a specific interface IP) to opt back into external exposure. The existing webhook-server.test.ts imported resolveListenConfig from the production module, but the symbol had never been extracted — the test was effectively dead. This commit lands the missing refactor and extends the test with the empty-string fallback, specific-interface, and combined-env-var cases. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Author
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.
Summary
resolveListenConfig(env)so the webhook listen address is environment-driven and unit-testable.bindto127.0.0.1so the webhook port (default3000) is not exposed to the LAN.WEBHOOK_BIND=0.0.0.0(or a specific interface IP) opts back into external exposure — typically a reverse proxy in front is preferable.server.listencall and includebindin the startup log line.src/webhook-server.test.tscovering the loopback default, port + bind env overrides, the empty-string fallback, a specific-interface bind, and combined env vars.Why
server.listen(port, '0.0.0.0', ...)atsrc/webhook-server.ts:121binds the webhook to all interfaces. The webhook handles inbound callbacks for any adapter that registers viaregisterWebhookAdapter(Telegram, Slack via Chat SDK proxy, etc.). There's no auth at the HTTP layer — the adapter handlers trust the request shape — so anything on the LAN that can reach the host port can hit the webhook routes directly.Defaulting to loopback closes that exposure for installs where the bot doesn't need to receive callbacks from outside the box. Installs that do need external callbacks (a real Telegram webhook from
api.telegram.org, or a Slack event-subscription URL) will typically front the webhook with a reverse proxy / tunnel anyway; for the rare cases where you want the bot to listen on a LAN IP directly,WEBHOOK_BIND=<ip>(or0.0.0.0) preserves the prior behavior.Compatibility
This changes the default listen address from
0.0.0.0to127.0.0.1. For most installs (where Telegram polling is used, or a reverse proxy fronts the webhook) this is transparent. Installs that relied on direct LAN access to the webhook port need either:WEBHOOK_BIND=0.0.0.0set explicitly (preserves prior behavior).Test plan
pnpm run build— cleanpnpm test src/webhook-server.test.ts— 6/6 pass; full suite 334/334 passss -ltnshows127.0.0.1:3000(not0.0.0.0:3000)WEBHOOK_BIND=0.0.0.0, restart, verify the listen address goes back to all-interfaces🤖 Generated with Claude Code