fix: reject tampered cursors and non-canonical UUIDs
decode_cursor checked only for KeyError, TypeError and ValueError, so a
server-issued cursor whose item id was replaced with [], {}, 123 or
false crashed UUID() with AttributeError and answered 500. It now checks
the types of "t" and "i" before parsing and accepts only the exact
string the server would issue for the parsed key: re-encoding must give
the received cursor, so v=true, an extra field or the id in another
notation is a 400 instead of a page.
pydantic's UUID also accepts ids without hyphens, with the urn:uuid:
prefix and in braces, wider than the contract's format: uuid. chat_id in
the path of the three chat endpoints and member_ids elements now use
UuidIn, which requires the 8-4-4-4-12 form in any case. Response models
and the OpenAPI schema are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -120,6 +120,16 @@ FastAPI 0.141 из `uv.lock`:
|
||||
`limit=0` и нечисловой → 400. Битый `cursor` → 400.
|
||||
- `member_ids`: 1–100 элементов, без дубликатов, все пользователи
|
||||
существуют, вызывающий в списке. Иначе 400.
|
||||
- UUID на входе — только запись 8-4-4-4-12 (`format: uuid`), цифры в
|
||||
любом регистре (спек `api-conventions`, «UUID на входе»). `UUID`
|
||||
pydantic шире контракта: принимает запись без дефисов, с `urn:uuid:` и
|
||||
в `{…}` (проверено на pydantic 2.13). Поэтому всё, что UUID передаёт
|
||||
клиент, — `chat_id` в пути и элементы `member_ids`, с лабы 4 и
|
||||
`attachment_ids`, — объявляется типом `UuidIn` из
|
||||
`src/api/schemas/common.py` (`BeforeValidator` с `UUID_PATTERN` и
|
||||
`re.fullmatch`), а не голым `UUID`. Модели ответов — обычный `UUID`.
|
||||
Не-строку `UuidIn` отдаёт валидатору `UUID`, и `[]`, `{}`, `123`,
|
||||
`false` дают 400 по типу.
|
||||
|
||||
## Аутентификация и сессии (лаба 2)
|
||||
|
||||
@@ -162,6 +172,13 @@ FastAPI 0.141 из `uv.lock`:
|
||||
или пользователя, битая base64 или JSON → 400. Последний элемент
|
||||
предыдущей страницы не повторяется. `limit` между страницами можно
|
||||
менять.
|
||||
- Курсор принимается только в записи, которую выдал сервер:
|
||||
`decode_cursor` после разбора собирает его заново (`encode_cursor`) и
|
||||
сравнивает со входом. Изменённый курсор — `"i"` не строка, тот же id в
|
||||
другой записи, `"v": true`, лишнее поле — 400, а не 500 и не страница
|
||||
(спек `pagination`, «Изменённый курсор»). Значения курсора до
|
||||
`UUID()` и `strptime` проверяются на тип: `UUID()` на не-строке роняет
|
||||
`AttributeError`, а не `ValueError` (change `strict-id-validation`).
|
||||
- Семантику при конкурентных вставках и ограничения часов описать в
|
||||
`REPORT.md` (например: `created_at` монотонен внутри чата).
|
||||
- В Postgres порядок и курсор задаёт SQL: сравнение кортежей
|
||||
|
||||
Reference in New Issue
Block a user