fix: patch CVE dependencies and path traversal risks

Upgrade aiohttp and related packages, harden local file and storage path checks, tighten password/JWT comparisons, and default Docker forwarded IP trust to empty.
This commit is contained in:
vastsa committed 2026-07-21 14:49:30 +08:00
1 parent c676458370
commit 00f3abd3b2
7 files changed
+199 -36

No files matched your search

+23 -11
View File
@@ -48,15 +48,20 @@ def create_token(data: dict, expires_in: int | None = None) -> str:
token_lifetime = (
get_admin_session_expire_seconds() if expires_in is None else expires_in
)
header = base64.b64encode(
json.dumps({"alg": "HS256", "typ": "JWT"}).encode()
).decode()
payload = base64.b64encode(
json.dumps({**data, "exp": int(time.time()) + token_lifetime}).encode()
).decode()
header = base64.urlsafe_b64encode(
json.dumps({"alg": "HS256", "typ": "JWT"}, separators=(",", ":")).encode()
).decode().rstrip("=")
payload = base64.urlsafe_b64encode(
json.dumps(
{**data, "exp": int(time.time()) + token_lifetime},
separators=(",", ":"),
).encode()
).decode().rstrip("=")
signature = hmac.new(_get_jwt_secret(), f"{header}.{payload}".encode(), "sha256").digest()
signature = base64.b64encode(signature).decode()
signature = hmac.new(
_get_jwt_secret(), f"{header}.{payload}".encode(), "sha256"
).digest()
signature = base64.urlsafe_b64encode(signature).decode().rstrip("=")
return f"{header}.{payload}.{signature}"
@@ -76,13 +81,20 @@ def verify_token(token: str) -> dict:
f"{header_b64}.{payload_b64}".encode(),
"sha256",
).digest()
expected_signature_b64 = base64.b64encode(expected_signature).decode()
expected_signature_b64 = (
base64.urlsafe_b64encode(expected_signature).decode().rstrip("=")
)
if not hmac.compare_digest(signature_b64, expected_signature_b64):
raise ValueError("无效的签名")
# 解码payload
payload = json.loads(base64.b64decode(payload_b64))
# 解码payload(兼容历史标准 base64 与 urlsafe base64)
padded = payload_b64 + "=" * (-len(payload_b64) % 4)
try:
payload_bytes = base64.urlsafe_b64decode(padded)
except Exception:
payload_bytes = base64.b64decode(padded)
payload = json.loads(payload_bytes)
# 检查是否过期
if payload.get("exp", 0) < time.time():