fix: ppclock-mcp --allowed-hosts 空串按 None 处理(空白名单自锁 localhost 421)

空串逗号拆分得空列表,TransportSecuritySettings(allowed_hosts=[]) 启用
DNS 重绑定防护后连 localhost 族一并 421。main() 解析层抽出
_parse_allowed_hosts,空列表以 or None 归一,保持 mcp 默认;含回归测试。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
chenweiandClaude committed 2026-07-31 01:02:07 +00:00
1 parent 85e2413947
commit d33a1296ff
2 files changed
+18 -2

No files matched your search

+10 -2
View File
@@ -34,6 +34,15 @@ def build_server(manager: DeviceManager,
return mcp
def _parse_allowed_hosts(value: str | None) -> list[str] | None:
"""解析 --allowed-hosts:None 原样返回;逗号拆分并去空白项。
空串(或拆分后全空)按 None 处理——空白名单会启用 DNS 重绑定防护
并连 localhost 族一并 421(空串自锁)。"""
if value is None:
return None
return [h.strip() for h in value.split(",") if h.strip()] or None
def parse_args(argv=None) -> argparse.Namespace:
p = argparse.ArgumentParser(prog="ppclock-mcp",
description="ppclock 墨水屏 MCP 服务器")
@@ -86,8 +95,7 @@ def main(argv=None) -> None:
manager = DeviceManager(mac=args.mac,
connect_timeout=args.connect_timeout,
idle_timeout=args.idle_timeout)
allowed_hosts = (None if args.allowed_hosts is None else
[h.strip() for h in args.allowed_hosts.split(",") if h.strip()])
allowed_hosts = _parse_allowed_hosts(args.allowed_hosts)
mcp = build_server(manager, allowed_hosts=allowed_hosts)
if args.transport == "stdio":
try: