From 5990576db9029374ebd401949108f23aaa1de5ea Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Sat, 30 May 2026 23:18:11 +0800 Subject: [PATCH] Potential fix for code scanning alert no. 89: Binding a socket to all network interfaces Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- astrbot/dashboard/server.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/astrbot/dashboard/server.py b/astrbot/dashboard/server.py index 159c7d673..e7e17551a 100644 --- a/astrbot/dashboard/server.py +++ b/astrbot/dashboard/server.py @@ -603,11 +603,17 @@ class AstrBotDashboard: def check_port_in_use(self, host: str, port: int) -> bool: """跨平台检测端口是否被占用""" - family = socket.AF_INET6 if ":" in host else socket.AF_INET + probe_host = host + if host in ("", "0.0.0.0"): + probe_host = "127.0.0.1" + elif host == "::": + probe_host = "::1" + + family = socket.AF_INET6 if ":" in probe_host else socket.AF_INET try: with socket.socket(family, socket.SOCK_STREAM) as s: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - s.bind((host, port)) + s.bind((probe_host, port)) return False except OSError as exc: if exc.errno == errno.EADDRINUSE: