Normalize fullwidth punctuation to ASCII across codebase.
Add scripts/normalize_ambiguous_unicode.py; fix corrupted patch_instance_theme_templates.py. Preserves curly quotes in string literals; removes Git homoglyph warnings on .env.example. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""中控 Web 登录:HUB_USERNAME + HUB_PASSWORD 配置后启用会话 Cookie。"""
|
||||
"""中控 Web 登录:HUB_USERNAME + HUB_PASSWORD 配置后启用会话 Cookie."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -26,7 +26,7 @@ def _env_password() -> str:
|
||||
|
||||
|
||||
def password_required() -> bool:
|
||||
"""默认启用登录(admin / admin123,可通过 .env 覆盖)。"""
|
||||
"""默认启用登录(admin / admin123,可通过 .env 覆盖)."""
|
||||
return True
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ def verify_credentials(username: str, password: str) -> bool:
|
||||
|
||||
|
||||
def verify_password(password: str) -> bool:
|
||||
"""兼容旧调用:仅校验密码、用户名用默认值。"""
|
||||
"""兼容旧调用:仅校验密码,用户名用默认值."""
|
||||
return verify_credentials(expected_username(), password)
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ def validate_session_token(token: str | None) -> bool:
|
||||
|
||||
|
||||
def cookie_secure_env_enabled() -> bool:
|
||||
"""是否在 .env 中启用「HTTPS 时带 Secure Cookie」策略。"""
|
||||
"""是否在 .env 中启用「HTTPS 时带 Secure Cookie」策略."""
|
||||
return (os.getenv("HUB_COOKIE_SECURE") or "").strip().lower() in (
|
||||
"1",
|
||||
"true",
|
||||
@@ -104,8 +104,8 @@ def cookie_secure_env_enabled() -> bool:
|
||||
|
||||
def cookie_secure_for_request(request) -> bool:
|
||||
"""
|
||||
仅在实际 HTTPS 访问时设置 Secure Cookie。
|
||||
这样可同时支持:域名 HTTPS 反代 + 内网 http://IP:5100 登录。
|
||||
仅在实际 HTTPS 访问时设置 Secure Cookie.
|
||||
这样可同时支持:域名 HTTPS 反代 + 内网 http://IP:5100 登录.
|
||||
"""
|
||||
if not cookie_secure_env_enabled():
|
||||
return False
|
||||
@@ -119,7 +119,7 @@ def cookie_secure_for_request(request) -> bool:
|
||||
|
||||
|
||||
def embed_allowed() -> bool:
|
||||
"""允许被本地导航等页面 iframe 嵌入(默认开启,内网场景)。"""
|
||||
"""允许被本地导航等页面 iframe 嵌入(默认开启,内网场景)."""
|
||||
return (os.getenv("HUB_ALLOW_EMBED") or "true").strip().lower() in (
|
||||
"1",
|
||||
"true",
|
||||
@@ -129,7 +129,7 @@ def embed_allowed() -> bool:
|
||||
|
||||
|
||||
def embed_frame_ancestors() -> str:
|
||||
"""CSP frame-ancestors;默认 *,可设 HUB_EMBED_ORIGINS=http://192.168.8.6:5070"""
|
||||
"""CSP frame-ancestors;默认 *,可设 HUB_EMBED_ORIGINS=http://192.168.8.6:5070"""
|
||||
raw = (os.getenv("HUB_EMBED_ORIGINS") or "*").strip()
|
||||
if raw == "*":
|
||||
return "*"
|
||||
@@ -139,7 +139,7 @@ def embed_frame_ancestors() -> str:
|
||||
|
||||
def set_session_cookie(response, request, token: str, *, embed: bool = False) -> None:
|
||||
"""
|
||||
embed=True:LocalNav 等跨站 iframe 嵌入时须 SameSite=None + Secure(仅 HTTPS 有效)。
|
||||
embed=True:LocalNav 等跨站 iframe 嵌入时须 SameSite=None + Secure(仅 HTTPS 有效).
|
||||
"""
|
||||
secure = cookie_secure_for_request(request)
|
||||
samesite = "lax"
|
||||
|
||||
Reference in New Issue
Block a user