relay: enforce ban/timeout write-block on command kinds - #3442
Open
Maxwellimus wants to merge 1 commit into
Open
relay: enforce ban/timeout write-block on command kinds#3442Maxwellimus wants to merge 1 commit into
Maxwellimus wants to merge 1 commit into
Conversation
ingest_event routed command kinds — DM open/add/hide, workflow define/trigger, approval grant/deny — straight to command_executor::handle_command and returned before the durable ban/timeout write-block gate that ordinary writes pass through. handle_command performs no restriction check of its own, so a banned or timed-out member could still open DMs, define or trigger workflows, and grant or deny approvals over signed POST /events. The moderation-command and relay-admin kinds are also routed around the shared gate, but each re-checks the ban inside its own handler; command kinds had no such check. Enforce the gate before routing command kinds. Command kinds are ordinary writes, not administrative capability, so they get the full gate including timeouts — the relay-admin timeout exemption does not extend to them. Extract the ban/timeout decision into restriction_block/enforce_moderation_restriction so the command-kind path and the ordinary-write path share one implementation and cannot drift; the restriction-state lookup fails closed on a DB error. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Max Lampert <maxwell@squareup.com>
Maxwellimus
marked this pull request as ready for review
July 29, 2026 03:24
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.
Summary
ingest_eventroutes command kinds — DM open/add/hide, workflowdefine/trigger, and approval grant/deny — straight to
command_executor::handle_commandand returns before the durableban/timeout write-block gate that ordinary writes pass through.
handle_commandperforms no restriction check of its own, so a memberwho has been banned or timed out could still:
by sending the corresponding signed event over
POST /events(or theWebSocket). The moderation-command and relay-admin kinds are also routed
around the shared gate, but each re-checks the ban inside its own
handler; command kinds were the one exempt path with no compensating
enforcement.
Fix
Enforce the durable ban/timeout write-block on command kinds before
routing to the executor:
403 blocked:.403 restricted:.Command kinds are ordinary writes, not administrative capability, so
an active timeout blocks them — the relay-admin timeout exemption does
not extend here.
The ban/timeout decision is extracted into
restriction_block/enforce_moderation_restriction, now the single source of truth sharedby both the command-kind path and the ordinary-write path, so the two
can't drift. The restriction-state lookup fails closed: a DB error
surfaces as
500 error:rather than admitting the write.Tests
restriction_block: banned →blocked:, activetimeout →
restricted:, expired timeout → no block, unrestricted → noblock.
#[ignore]d e2e regression test(
regression_command_kind_ban_gate.rs): against a live relay, abanned member and a timed-out member each have their
DM_OPENcommandrefused (403 with the exact wire contract) and create no DM channel,
while an unrestricted member's
DM_OPENstill succeeds and mutates.Pre-fix, the banned member's
DM_OPENis accepted (200) — the testfails on that assertion.
🤖 Generated with Claude Code