fix(matrix): fail-closed approval reaction auth (parity with Telegram) - #34567
Merged
Conversation
…SERS is empty
The _on_reaction approval handler used:
if self._allowed_user_ids and sender not in self._allowed_user_ids:
When MATRIX_ALLOWED_USERS is not configured, _allowed_user_ids is an
empty set. The short-circuit on the empty set caused the deny block to
never execute, allowing any Matrix room member to approve or deny tool
calls via ✅/❎ reactions — even users that run.py's _is_user_authorized
would reject for regular messages.
Fix mirrors the Telegram _is_callback_user_authorized fix (commit
89d3205, PR #28494): deny by default when no allowlist is configured,
unless GATEWAY_ALLOW_ALL_USERS=true is explicitly set.
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-import |
1 |
unresolved-attribute |
1 |
First entries
tests/gateway/test_matrix_approval_reaction_fail_closed.py:16: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
tests/gateway/test_matrix_approval_reaction_fail_closed.py:88: [unresolved-attribute] unresolved-attribute: Unresolved attribute `resolve_gateway_approval` on type `ModuleType`
✅ Fixed issues: none
Unchanged: 4899 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
Collaborator
1 task
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.
The bug (confirmed live on main)
gateway/platforms/matrix.py:2239gated approval reactions with:When
MATRIX_ALLOWED_USERSis empty,self._allowed_user_idsis falsy, thewhole guard short-circuits, and any user in the room can resolve a
dangerous-command approval prompt — fail-open.
The fix
Fail-closed by default; the deliberate-open-access operator
(
GATEWAY_ALLOW_ALL_USERS=true) is explicitly preserved. Mirrors thealready-shipped Telegram callback-auth shape (
_is_callback_user_authorized,telegram.py:558— sameGATEWAY_ALLOW_ALL_USERSfallback).No regression — every supported config preserved
MATRIX_ALLOWED_USERSset (solo/team operator)/pairGATEWAY_ALLOW_ALL_USERS=true(deliberate open)The only behavior that changes is the last row — and those senders can't pass
Layer-1 admission (
_is_user_authorizeddefaults to deny) to issue a commandin the first place, so no legitimate user loses anything. The bug was an
inconsistency where an unauthorized user could still approve a prompt they
were never authorized to touch.
Verification
tests/gateway/test_matrix_approval_reaction_fail_closed.py— 4 tests, allpass on current main:
test_no_allowlist_no_allow_all_denies— the bug, now closedtest_no_allowlist_allow_all_permits— no-regression guard (allow-all operator keeps open approvals)test_listed_sender_permits/test_unlisted_sender_denies— allowlist path unchangedPart of the approval-gate-bypass cluster (issue #32877 names the single-gate
problem; this closes the Matrix reaction-auth surface). Salvage of #30062.
Closes #30062
Co-authored-by: EloquentBrush0x 283442588+EloquentBrush0x@users.noreply.github.com