Add bounded private image upload with safe S3 persistence

This commit is contained in:
Самохвалов Андрей Ремович
2026-10-02 13:24:51 +03:00
parent 22f7bcddf5
commit 412b465b85
13 changed files with 430 additions and 8 deletions
+2 -1
View File
@@ -37,7 +37,8 @@ def error_response(request: Request, status: int, extra_headers: dict | None = N
@app.middleware("http")
async def request_contract(request: Request, call_next):
request.state.request_id = str(uuid4())
if request.method == "POST" and request.url.path.startswith("/api/v1/") and request.url.path != "/api/v1/auth/sessions":
is_upload = request.url.path.startswith("/api/v1/chats/") and request.url.path.endswith("/attachments")
if request.method == "POST" and request.url.path.startswith("/api/v1/") and request.url.path != "/api/v1/auth/sessions" and not is_upload:
media_type, _, charset = request.headers.get("content-type", "").lower().partition(";")
if media_type.strip() != "application/json" or (charset and charset.strip() != "charset=utf-8"):
return error_response(request, 415)