fix: address auth-hardening verify findings

Drop the body-limit rule from HAProxy (user decision 2026-11-18): the
replica middleware answers 400 with X-Instance-Id, tests require the
header again. Widen the failure_checks selection in the trust matrix,
name 13fdd18 in the evidence header, document Valkey LRU eviction of
login counters and the allowlist as trusted X-Forwarded-For senders,
check waited_ms of KDF budget rejections in the queue scenario.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 10:31:57 +03:00
co-authored by Claude Opus 5.5
parent 4d117f0297
commit 3f4771c9d9
22 changed files with 372 additions and 127 deletions
+5 -10
View File
@@ -101,16 +101,11 @@ frontend entry
# один адрес. Реплика верит заголовку только от соединения с identity
# haproxy (allowlist после рукопожатия mTLS), в консоли — не верит
http-request set-header X-Forwarded-For %[src]
# предел размера тела вне загрузки вложения (change auth-hardening,
# design, решение 8): Content-Length больше 65536 — 400 в формате
# контракта, тело к реплике не идёт. Число — REQUEST_BODY_MAX_BYTES
# (src/utils/constants.py), выражение пути — то же, что у set-timeout
# backend api (UPLOAD_PATH_PATTERN): на пути загрузки свой предел
# сервиса и порядок 404 → 415 → 413. Тело частями без Content-Length
# ограничивает реплика
acl upload method POST
acl upload_path path_reg ^/api/v1/chats/[^/]+/attachments$
http-request return status 400 content-type application/json lf-string '{"error":{"code":"invalid_request","message":"Request body is too large","request_id":"%[unique-id]"}}' hdr X-Request-Id "%[unique-id]" if { req.hdr_val(content-length) gt 65536 } !upload || { req.hdr_val(content-length) gt 65536 } !upload_path
# предела размера тела здесь нет (решение пользователя 2026-11-18,
# verify W1 change auth-hardening): ответ LB был бы без X-Instance-Id, а
# контракт допускает это только у ошибок соединения LB. Тело больше
# REQUEST_BODY_MAX_BYTES отклоняет реплика — по Content-Length до чтения
# тела, частями — счётчиком (src/api/middlewares/body_limit.py)
default_backend api
backend api