Skip to content

Commit 5990576

Browse files
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>
1 parent 1b1ae10 commit 5990576

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

astrbot/dashboard/server.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,17 @@ def _get_required_open_api_scope(path: str) -> str | None:
603603

604604
def check_port_in_use(self, host: str, port: int) -> bool:
605605
"""跨平台检测端口是否被占用"""
606-
family = socket.AF_INET6 if ":" in host else socket.AF_INET
606+
probe_host = host
607+
if host in ("", "0.0.0.0"):
608+
probe_host = "127.0.0.1"
609+
elif host == "::":
610+
probe_host = "::1"
611+
612+
family = socket.AF_INET6 if ":" in probe_host else socket.AF_INET
607613
try:
608614
with socket.socket(family, socket.SOCK_STREAM) as s:
609615
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
610-
s.bind((host, port))
616+
s.bind((probe_host, port))
611617
return False
612618
except OSError as exc:
613619
if exc.errno == errno.EADDRINUSE:

0 commit comments

Comments
 (0)