Spaces:
Sleeping
Sleeping
Commit ·
56659e7
1
Parent(s): 629b5a3
minor security fixes
Browse files
backend/app/api/routes/admin/helpers.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from datetime import datetime, timezone
|
|
|
|
| 2 |
from urllib.parse import urlencode
|
| 3 |
|
| 4 |
from fastapi import HTTPException, UploadFile
|
|
@@ -56,7 +57,10 @@ async def read_upload_bytes(
|
|
| 56 |
) -> bytes:
|
| 57 |
"""Read and validate an uploaded file, enforcing size and format constraints."""
|
| 58 |
if allowed_extensions and file.filename:
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
if ext not in allowed_extensions:
|
| 61 |
raise HTTPException(
|
| 62 |
status_code=400,
|
|
|
|
| 1 |
from datetime import datetime, timezone
|
| 2 |
+
import os
|
| 3 |
from urllib.parse import urlencode
|
| 4 |
|
| 5 |
from fastapi import HTTPException, UploadFile
|
|
|
|
| 57 |
) -> bytes:
|
| 58 |
"""Read and validate an uploaded file, enforcing size and format constraints."""
|
| 59 |
if allowed_extensions and file.filename:
|
| 60 |
+
secure_name = os.path.basename(file.filename.replace("\\", "/"))
|
| 61 |
+
if "." not in secure_name:
|
| 62 |
+
raise HTTPException(status_code=400, detail="File must have an extension")
|
| 63 |
+
ext = secure_name.rsplit(".", 1)[-1].lower()
|
| 64 |
if ext not in allowed_extensions:
|
| 65 |
raise HTTPException(
|
| 66 |
status_code=400,
|
backend/app/core/config.py
CHANGED
|
@@ -92,13 +92,7 @@ class Settings(BaseSettings):
|
|
| 92 |
CLOUDINARY_API_SECRET: str = ""
|
| 93 |
|
| 94 |
@model_validator(mode="after")
|
| 95 |
-
def
|
| 96 |
-
if self.SECRET_KEY == "change-me-in-production-32-chars-minimum":
|
| 97 |
-
raise ValueError(
|
| 98 |
-
"SECRET_KEY is still set to the placeholder value. "
|
| 99 |
-
"Generate a real secret directly into your .env file:\n"
|
| 100 |
-
' python3 -c "import secrets; open(\'.env\', \'a\').write(f\'SECRET_KEY={secrets.token_hex(32)}\\n\')"'
|
| 101 |
-
)
|
| 102 |
if len(self.SECRET_KEY) < 32:
|
| 103 |
raise ValueError("SECRET_KEY must be at least 32 characters.")
|
| 104 |
return self
|
|
|
|
| 92 |
CLOUDINARY_API_SECRET: str = ""
|
| 93 |
|
| 94 |
@model_validator(mode="after")
|
| 95 |
+
def _validate_secret_key(self) -> "Settings":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
if len(self.SECRET_KEY) < 32:
|
| 97 |
raise ValueError("SECRET_KEY must be at least 32 characters.")
|
| 98 |
return self
|