From 9540f51dce5210dc8d778812a6d082703f3a2e1b Mon Sep 17 00:00:00 2001 From: Jinpy Date: Tue, 29 Sep 2026 14:08:54 +0800 Subject: [PATCH] fix(web): make the listener bind address configurable via DBX_BIND_ADDR --- crates/dbx-web/src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/dbx-web/src/main.rs b/crates/dbx-web/src/main.rs index ac93da5ed1..b0edc80a5a 100644 --- a/crates/dbx-web/src/main.rs +++ b/crates/dbx-web/src/main.rs @@ -8,7 +8,7 @@ mod state; mod web_mcp; use std::collections::{HashMap, HashSet}; -use std::net::SocketAddr; +use std::net::{IpAddr, SocketAddr}; use std::sync::Arc; use argon2::password_hash::rand_core::OsRng; @@ -1398,7 +1398,19 @@ async fn serve() { // Bind address let port: u16 = std::env::var("DBX_PORT").ok().and_then(|p| p.parse().ok()).unwrap_or(4224); - let addr = SocketAddr::from(([0, 0, 0, 0], port)); + // Defaults to all interfaces for container deployments; operators who + // expose the service through a local reverse proxy can pin the listener + // (DBX_BIND_ADDR=127.0.0.1) without a firewall change. The value is an + // IP only — the port always comes from DBX_PORT so the HTTP listener and + // the Redis PubSub server (which reads DBX_PORT independently) stay in + // sync. + let ip = match std::env::var("DBX_BIND_ADDR").ok().as_deref().map(str::trim).filter(|value| !value.is_empty()) { + Some(value) => { + value.parse::().unwrap_or_else(|error| panic!("invalid DBX_BIND_ADDR \"{value}\": {error}")) + } + None => IpAddr::from([0, 0, 0, 0]), + }; + let addr = SocketAddr::new(ip, port); tracing::info!("DBX Web server starting on http://{}", addr); if public_base_path != "/" {