fix: address attachments verify findings

- keep one upload body in memory: BytesIO + getvalue() without copy,
  fixed glibc mmap threshold in the image (no realloc copy on growth)
- stop PNG inflate at expected size + 1 byte
- reject filename that is not valid UTF-8 after percent-decoding (400)
- failure stand: env limit variables do not change attachment limits;
  history with attachment_ids while S3 is stopped
- drop dead constants; restate "old image on new schema" scenario

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 02:16:49 +03:00
co-authored by Claude Opus 5.5
parent 8dc925e8ca
commit dba40bc325
23 changed files with 398 additions and 47 deletions
+4 -1
View File
@@ -74,7 +74,10 @@ FastAPI, один процесс на реплику; реплик ≥2 за HAP
асинхронным итератором поверх `request.stream()`, обёртка переводит
`ClientDisconnect` в доменное `UploadInterrupted` (400): в итоговой
записи 400, а не 500 с traceback. `Content-Type` — тип до `;`, без
пробелов, в нижнем регистре; `Content-Length` — `int` или `None`;
пробелов, в нижнем регистре; `Content-Length` — `int` или `None`.
До сервиса ручка проверяет кодировку `filename` по сырой строке
запроса (`_check_filename_encoding` → `InvalidFilename`, 400):
Starlette заменил бы неверный UTF-8 на U+FFFD (`api-contract.md`);
- скачивание — `StreamingResponse` над генератором блоков объекта S3:
`media_type` вложения (у `image/*` Starlette `charset` не добавляет),
`Content-Length`, `X-Content-Type-Options: nosniff`; генератор сам