管理端IP白名单支持 * 通配符全放行(仅token鉴权):XL_ADMIN_IPS=* 此前不被解析,配了不生效

This commit is contained in:
2026-11-23 14:09:16 +08:00
parent 6c44632cc9
commit 3652c11f3b
+2 -2
View File
@@ -24,8 +24,8 @@ ALLOWED_IPS = {"127.0.0.1", "::1", "localhost", "testclient"} | {s.strip() for s
def verify_admin(request: Request, x_admin_token: str | None = Header(default=None)):
ip = request.client.host if request.client else "?"
# 支持网段前缀:白名单条目以 . 结尾时按前缀匹配(如 "192.168.31.")
ok_ip = any(
# "*" = 全放行(仅靠 token 鉴权);网段前缀:白名单条目以 . 结尾时按前缀匹配(如 "192.168.31.")
ok_ip = "*" in ALLOWED_IPS or any(
ip == w or (w.endswith(".") and ip.startswith(w))
for w in ALLOWED_IPS
)