🐛 fix: 整合官方 2.7.1 修复并升级定制版本
* 校验变更的出站地址并保留现有内部 CloudDrive 配置 * 修复未知长度上传、API 404 语义及下载令牌比较 * 合并 S3 小分片为符合最小尺寸要求的 multipart 部分 * 同步官方运行依赖、版本元数据和已推送前端版本 * 验证单元集成、覆盖率及定制上传下载兼容并记录整合范围
This commit is contained in:
1 parent
9ce9810b3b
commit
3b6949d862
14 files changed
+355
-31
No files matched your search
+15
-1
@@ -20,7 +20,8 @@ from core.settings import (
|
||||
settings,
|
||||
)
|
||||
from core.config import refresh_settings
|
||||
from core.security import INTERNAL_CONFIG_KEYS, generate_jwt_secret
|
||||
from core.security import (INTERNAL_CONFIG_KEYS, generate_jwt_secret,
|
||||
OUTBOUND_ENDPOINT_CONFIG_KEYS, validate_outbound_endpoint, validate_outbound_hostname)
|
||||
from apps.base.models import FileCodes, KeyValue, ShareCodeReservations, TransferStats, file_codes_pydantic
|
||||
|
||||
from apps.base.utils import get_expire_info, get_random_code, validate_expire_style
|
||||
@@ -1855,6 +1856,19 @@ class ConfigService:
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
# Existing internal NAS/CloudDrive endpoints remain valid for unrelated saves.
|
||||
# Validate only changed destinations, matching upstream 2.7.1 semantics.
|
||||
for endpoint_key in OUTBOUND_ENDPOINT_CONFIG_KEYS:
|
||||
candidate = str(next_config.get(endpoint_key) or "")
|
||||
current = str(current_config.get(endpoint_key) or "")
|
||||
if candidate == current:
|
||||
continue
|
||||
validator = validate_outbound_hostname if endpoint_key == "s3_hostname" else validate_outbound_endpoint
|
||||
try:
|
||||
next_config[endpoint_key] = await asyncio.to_thread(validator, candidate)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(400, str(exc)) from exc
|
||||
|
||||
if admin_password_changed:
|
||||
next_config["jwt_secret"] = generate_jwt_secret()
|
||||
|
||||
|
||||
+11
-6
@@ -1,5 +1,7 @@
|
||||
import datetime
|
||||
import asyncio
|
||||
import hashlib
|
||||
import hmac
|
||||
from io import BytesIO
|
||||
import os
|
||||
import uuid
|
||||
@@ -101,9 +103,12 @@ class FileUploadService:
|
||||
async def validate_file_size(file: UploadFile, max_size: int) -> int:
|
||||
size = file.size
|
||||
if size is None:
|
||||
await file.seek(0, 2) # type: ignore[arg-type]
|
||||
size = file.file.tell()
|
||||
await file.seek(0)
|
||||
def measure():
|
||||
file.file.seek(0, 2)
|
||||
size = file.file.tell()
|
||||
file.file.seek(0)
|
||||
return size
|
||||
size = await asyncio.to_thread(measure)
|
||||
if size > max_size:
|
||||
max_size_mb = max_size / (1024 * 1024)
|
||||
raise HTTPException(
|
||||
@@ -384,11 +389,11 @@ async def download_file(key: str, code: str, ip: str = Depends(ip_limit["error"]
|
||||
file_storage: FileStorageInterface = storages[settings.file_storage]()
|
||||
normalized_code = normalize_share_code(code)
|
||||
# 同时接受当前窗口与上一窗口 token,避免时间窗边界竞态导致偶发 403
|
||||
valid_keys = {
|
||||
valid_keys = [
|
||||
await get_select_token(normalized_code, offset=0),
|
||||
await get_select_token(normalized_code, offset=1),
|
||||
}
|
||||
if key not in valid_keys:
|
||||
]
|
||||
if not any(hmac.compare_digest(key.encode(), candidate.encode()) for candidate in valid_keys):
|
||||
ip_limit["error"].add_ip(ip)
|
||||
raise HTTPException(status_code=403, detail="下载鉴权失败")
|
||||
has, file_code = await get_code_file_by_code(normalized_code)
|
||||
|
||||
Reference in new issue
Block a user