瀏覽代碼

fix: enhance filename validation and extraction in FileService #16867 (#16869)

tags/1.2.0
GuanMu 7 月之前
父節點
當前提交
d65da600e5
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 7 行新增1 行删除
  1. 7
    1
      api/services/file_service.py

+ 7
- 1
api/services/file_service.py 查看文件

@@ -1,5 +1,6 @@
import datetime
import hashlib
import os
import uuid
from typing import Any, Literal, Union

@@ -38,7 +39,12 @@ class FileService:
source_url: str = "",
) -> UploadFile:
# get file extension
extension = filename.split(".")[-1].lower()
extension = os.path.splitext(filename)[1].lstrip(".").lower()

# check if filename contains invalid characters
if any(c in filename for c in ["/", "\\", ":", "*", "?", '"', "<", ">", "|"]):
raise ValueError("Filename contains invalid characters")

if len(filename) > 200:
filename = filename.split(".")[0][:200] + "." + extension


Loading…
取消
儲存