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:
1 parent
c676458370
commit
00f3abd3b2
7 files changed
+199
-36
No files matched your search
+31
-4
@@ -1,4 +1,5 @@
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
import os
|
||||
import time
|
||||
import uuid
|
||||
@@ -1627,9 +1628,35 @@ class LocalFileService:
|
||||
|
||||
class LocalFileClass:
|
||||
def __init__(self, file):
|
||||
self.file = file
|
||||
self.path = data_root / "local" / file
|
||||
if os.path.exists(self.path):
|
||||
# 仅允许 data/local 目录下的单层文件名,阻断路径穿越与绝对路径访问。
|
||||
raw_name = str(file or "")
|
||||
normalized = Path(raw_name).as_posix()
|
||||
# 输入本身不得包含路径分隔符或绝对路径形态。
|
||||
if (
|
||||
not raw_name
|
||||
or raw_name in {".", ".."}
|
||||
or normalized in {".", ".."}
|
||||
or "/" in normalized
|
||||
or normalized.startswith("~")
|
||||
or Path(raw_name).is_absolute()
|
||||
or Path(raw_name).name != raw_name
|
||||
):
|
||||
raise HTTPException(status_code=400, detail="非法文件名")
|
||||
|
||||
safe_name = Path(raw_name).name
|
||||
if not safe_name or safe_name in {".", ".."}:
|
||||
raise HTTPException(status_code=400, detail="非法文件名")
|
||||
|
||||
local_root = (data_root / "local").resolve()
|
||||
candidate = (local_root / safe_name).resolve()
|
||||
try:
|
||||
candidate.relative_to(local_root)
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=400, detail="非法文件路径")
|
||||
|
||||
self.file = safe_name
|
||||
self.path = candidate
|
||||
if self.path.is_file():
|
||||
self.ctime = time.strftime(
|
||||
"%Y-%m-%d %H:%M:%S", time.localtime(os.path.getctime(self.path))
|
||||
)
|
||||
@@ -1649,4 +1676,4 @@ class LocalFileClass:
|
||||
os.remove(self.path)
|
||||
|
||||
async def exists(self):
|
||||
return os.path.exists(self.path)
|
||||
return self.path.is_file()
|
||||
Reference in new issue
Block a user