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 -15
View File
@@ -142,15 +142,10 @@ def assert_accepted(resp: httpx.Response) -> dict[str, Any]:
return attachment
def assert_error(
resp: httpx.Response,
status: int,
*,
instance_id: bool = True,
) -> dict[str, Any]:
def assert_error(resp: httpx.Response, status: int) -> dict[str, Any]:
"""Ошибка в формате контракта; `code` соответствует статусу."""
assert resp.status_code == status, describe(resp, f"expected {status}")
body = json_body(resp, instance_id=instance_id)
body = json_body(resp)
check_body(body, "Error")
error = body["error"]
assert error["code"] == ERROR_CODES[status], describe(
@@ -319,16 +314,11 @@ def assert_replicas(values: Iterable[str], expected: int) -> set[str]:
return seen
def json_body(resp: httpx.Response, *, instance_id: bool = True) -> Any:
"""JSON-тело в UTF-8, непустые `X-Request-Id` и `X-Instance-Id`.
`instance_id=False` — ответ мог построить сам LB (предел тела, change
auth-hardening): у его ответов `X-Instance-Id` нет, контракт допускает.
"""
def json_body(resp: httpx.Response) -> Any:
"""JSON-тело в UTF-8, непустые `X-Request-Id` и `X-Instance-Id`."""
request_id = resp.headers.get("X-Request-Id", "")
assert request_id.strip(), describe(resp, "no X-Request-Id")
if instance_id:
assert_instance_id(resp)
assert_instance_id(resp)
media_type, _, params = resp.headers.get("Content-Type", "").partition(
";",
)
+4 -3
View File
@@ -518,9 +518,10 @@ def test_declared_body_over_limit(
content=body,
headers=headers,
)
# через LB отказывает LB: X-Instance-Id у его ответа нет
# отказывает реплика по Content-Length, не читая тело (решение
# пользователя 2026-11-18: предела в LB нет), — с X-Instance-Id
for resp in (with_auth, without_auth):
error = assert_error(resp, 400, instance_id=False)
error = assert_error(resp, 400)
assert error["message"] == "Request body is too large"
assert api.all_messages(alice, chat["id"]) == []
@@ -537,7 +538,7 @@ def test_chunked_body_over_limit(
content=_chunks(BODY_MAX_BYTES + 8192),
headers={"Content-Type": "application/json"},
)
# Content-Length нет — LB тело не меряет, отказывает реплика
# Content-Length нет — реплика меряет тело счётчиком
error = assert_error(resp, 400)
assert error["message"] == "Request body is too large"
assert_instance_id(resp)
+4 -3
View File
@@ -121,8 +121,9 @@ def test_broken_basic(api: Api, alice: Actor) -> None:
@pytest.mark.spec("sessions", "Большое тело входа")
def test_login_large_body(api: Api, alice: Actor) -> None:
"""Предел размера тела (change auth-hardening, решение 8): верный Basic с
телом больше 64 KiB — 400 до проверки credentials; через LB отказывает
LB (без X-Instance-Id)."""
телом больше 64 KiB — 400 до проверки credentials; отказывает реплика по
Content-Length, с X-Instance-Id (предела в LB нет — решение пользователя
2026-11-18)."""
headers = {
"Authorization": basic_header(
f"{alice.username}:{alice.password}".encode(),
@@ -135,7 +136,7 @@ def test_login_large_body(api: Api, alice: Actor) -> None:
headers=headers,
content=b" " * 65537,
)
error = assert_error(resp, 400, instance_id=False)
error = assert_error(resp, 400)
assert error["message"] == "Request body is too large"
assert "token" not in resp.text