Repository navigation
feat: relay-wide long-poll cap and audit trail for cap rejections (M2/M4) - #93
Merged
Merged
Conversation
…/M4) Two gaps remained after the per-identity long-poll cap (9b622e8): 1. The per-identity cap alone does not bound the total: the participant manifest is hot-reloadable (issue #36), so 2 x roles grows without a relay restart. Add maxConcurrentLongPollsGlobal (default 32) checked across all identities, same RATE_LIMITED rejection. 2. A rejected acquire was invisible: the DoS-relevant event left no trace. The HTTP layer now records a longPoll/deny audit event with the route that hit the cap before failing the request closed (additive AuditedAction extension, local jsonl only, protocol v1 untouched). Rejections are request-bounded, so the log cannot be flooded through them. Tests: relay-wide cap unit test (fills across identities, release reopens), HTTP tests pin the audit line for both long-poll routes and the silence of instant polls. Deliberately not audited: per-message authorization refusals on the delivery routes (message ids are unguessable UUIDs; noise/signal not worth it).
Owner
Author
Review (dev) — ACCEPTChecked against the agreed plan (G1 audit as core, G2 global cap included, G3 explicitly out):
Verified independently in a detached review worktree: protection + http suites 56/56, full Non-blocking note: caps are in-memory per relay process (reset on restart/re-election) — documented in the PR as accepted local-first behavior, consistent with the security review. Passing to CTO for final. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Контекст
Приоритеты CTO по
docs/security/review-2026-11-12.md: (a) M2 — лимит конкурентных long-poll на relay (bounded, fail-closed, с диагностикой); (b) M4 — полный audit log.Аудит покрытия M4 по коду HEAD
82bd914: auth failures (401 →authenticate/deny), operator pause/resume, replaceSession, token issue/rotate/revoke, registerSession (с surface), claim, directory degraded/recovered, deny по send/reply/inbox/acknowledge/getMessage — всё уже записывается предыдущими волнами (#3, #42, #53, #36). Фактических пробелов осталось два, оба вокруг M2.Изменения
1. Relay-wide cap на конкурентные long-poll (M2, bounded)
Per-identity cap 2 (9b622e8) ограничивает суммарно
2 × roles, но manifest hot-reloadable (#36) — роли могут добавляться без рестарта relay, и глобальная граница плывёт. ДобавленProtectionLimits.maxConcurrentLongPollsGlobal(default 32): суммарный счётчик по всем идентичностям, тот жеRATE_LIMITEDповерх → 429 (существующийmapError).2. Audit-диагностика отказов капа (M2, «с диагностикой»)
Отклонённый acquire — DoS-релевантное событие — раньше не оставлял следа. Теперь HTTP-слой записывает
longPoll/deny/RATE_LIMITEDс маршрутом вdetail(GET /v1/inbox/GET /v1/deliveries/next) до закрытия запроса.AuditedActionрасширен аддитивно ("longPoll"); локальный jsonl, протокол v1 и wire-контракты не тронуты. Отказы request-bounded — флуда лога через них нет. Doctor видит события через существующий audit tail (#3).Осознанно НЕ сделано
Per-message authz-отказы (403) на
/v1/deliveries/{authorize,receipt,failure}не аудируются: пространство message-id — неперебираемые UUID, легитимные клиенты туда не попадают, шум/сигнал сомнителен (решение согласовано с dev в треде 53aef786).Тесты
test/relay/protection.test.ts: relay-wide cap заполняется разными идентичностями, 4-й acquire →RATE_LIMITED, release переоткрывает окно.test/transport/http.test.ts: 3-й параллельный inbox long-poll → 429 + ровно одна audit-строкаlongPollс маршрутом; то же для delivery-маршрута; instant polls (waitMs=0) не трогают кап и не пишут в audit.pnpm verifyзелёный: 104 файла / 905 тестов, format/typecheck/build чистые.Документация
docs/backlog.md: строка M2 закрыта с учётом hardening.Ограничения