Skip to content

fix(matrix): reject unmatchable autoJoinAllowlist entries - #161607

Merged
obviyus merged 1 commit into
openclaw:mainfrom
xydigitLybnnnn:fix/160951-matrix-autojoin-allowlist
Oct 7, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
xydigitLybnnnn:fix/160951-matrix-autojoin-allowlist

Conversation

@xydigitLybnnnn

@xydigitLybnnnn xydigitLybnnnn commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Issue #160951 — channels.matrix.autoJoinAllowlist accepts and validates Matrix user IDs (@user:server), but the invite handler never compares against the inviting user. It only matches room IDs (!…), aliases (#…), or *. A user-ID entry validates cleanly, is persisted, and then silently ignores every invite; the only trace was logVerbose (off by default).

Two things make this the worst pairing for operators:

  • autoJoinAllowlist sits beside dm.allowFrom, which is a user-ID list, so a user ID reads as the natural value.
  • A room-ID allowlist cannot auto-join a DM by construction — clients mint a fresh room ID per DM, so it can never be known in advance. For DMs the option is unusable as implemented, which pushes operators toward exactly the value that silently fails.

Root cause

extensions/matrix/src/matrix/monitor/auto-join.ts — onInvite(roomId, _inviteEvent) never inspects the inviter, and the allowlist test is:

autoJoinAllowlist.has("*") ||
  allowedRoomIds.has(roomId) ||
  allowedAliasRoomIds.some((resolvedRoomId) => resolvedRoomId === roomId)

allowedRoomIds collects !-prefixed entries and allowedAliases collects #-prefixed entries, so any @-prefixed entry falls through every branch. The only signal for an ignored invite was logVerbose, which is silent at the default log level.

The fix

Warn without blocking (the recommended route from review). This change does not tighten channels.matrix.autoJoinAllowlist, so a saved user-ID entry keeps loading and an existing installation is not broken on update. Instead:

  • extensions/matrix/src/matrix/target-ids.ts — the shared Matrix target contract now exposes isMatrixInviteAutoJoinTarget(): the wildcard, a literal room ID, or a full #alias:server with a non-empty local part and server name (so #ops:, #:example.org, and #missing-server are all inert). This is the same predicate the setup wizard already enforced for the field, promoted to the target-ids owner so config, setup, and runtime cannot drift.
  • extensions/matrix/src/onboarding.ts — imports the shared predicate and drops its private copy; the wizard keeps re-prompting on invalid entries, now from the single owner.
  • extensions/matrix/src/matrix/monitor/auto-join.ts — when autoJoin: "allowlist" holds entries that can never match an invited room, the handler emits one warning naming them through the plugin logger (default level). It fires once at registration, not per invite, so it cannot spam. This also covers account-scoped config (channels.matrix.accounts.<id>), which is schema-open and has no separate validation.

Docs (docs/channels/matrix/setup.md, docs/channels/matrix.md) now state that non-room entries cannot match and are warned about, and that sender authorization belongs in dm.allowFrom.

Evidence

1. Gateway path, BEFORE (exit 1) → AFTER (exit 0)

Harness: harness/gateway-autojoin-repro.mts, run with node --import ./scripts/tsx.mjs. It writes a real saved config file, loads it through the real Gateway config loader (loadConfig from src/config/io.runtime.ts), resolves the Matrix account config with the real resolveMatrixAccountConfig, and drives the real registerMatrixAutoJoin handler with a Matrix client boundary stub emitting a real room.invite event.

This proves the saved user-ID entry still loads (no INVALID_CONFIG, no migration needed) and that the inert entry is now reported.

$ git restore --source=HEAD~1 -- extensions/matrix/src/matrix/monitor/auto-join.ts \
    extensions/matrix/src/matrix/target-ids.ts extensions/matrix/src/onboarding.ts   # pre-fix files
$ node --import ./scripts/tsx.mjs issue-160951-gateway-repro.mts ; echo "exit=$?"
Gateway config load (real loader, saved user-ID allowlist)
  loadConfig: OK (config accepted)
  autoJoin: "allowlist"
  autoJoinAllowlist: ["@ryan:example.org"]
Matrix invite handling
  joined: []
  default-level logs: (none)
  RESULT: inert allowlist is silent after a real config load
REPRO_RESULT: failure (no diagnostic for the inert allowlist)
before_exit=1
$ node --import ./scripts/tsx.mjs issue-160951-gateway-repro.mts ; echo "exit=$?"      # this branch
Gateway config load (real loader, saved user-ID allowlist)
  loadConfig: OK (config accepted)
  autoJoin: "allowlist"
  autoJoinAllowlist: ["@ryan:example.org"]
Matrix invite handling
  joined: []
  default-level logs: ["warn: matrix: autoJoinAllowlist entries cannot match an invited room and are ignored: @ryan:example.org"]
  RESULT: inert allowlist reported after a real config load
REPRO_RESULT: success
after_exit=0

The config result is identical in both runs (loadConfig: OK) — the saved configuration remains loadable, so there is no upgrade breakage. The only delta is the new default-level diagnostic.

Transcripts: harness/gateway-before-fix.txt, harness/gateway-after-fix.txt; combined transcript in terminal-output.txt.

2. Target suites

$ node scripts/run-vitest.mjs run extensions/matrix/src/matrix/monitor/auto-join.test.ts \
    extensions/matrix/src/matrix/target-ids.test.ts extensions/matrix/src/onboarding.test.ts
 ✓  registerMatrixAutoJoin > warns once when the allowlist holds an entry that can never match a room
 ✓  registerMatrixAutoJoin > does not warn for room, alias, or wildcard allowlist entries
 ✓  registerMatrixAutoJoin > warns about malformed prefixed entries the room matcher can never use
 ✓  registerMatrixAutoJoin > does not warn when auto-join does not consult the allowlist
 ✓  registerMatrixAutoJoin > ignores an unmatchable user-ID allowlist entry without joining
 ✓  isMatrixInviteAutoJoinTarget > classifies "!ops:example.org" as matchable=true
 ✓  isMatrixInviteAutoJoinTarget > classifies "#ops:" as matchable=false
 ✓  isMatrixInviteAutoJoinTarget > classifies "#:example.org" as matchable=false
 Test Files  3 passed (3)
      Tests  47 passed (47)

Measured cost (local, Linux x64): the three changed Matrix test files run as one Vitest shard in 105 s wall (worker/transform ~88%, tests ~1%); the added table cases are negligible. Only auto-join.test.ts and target-ids.test.ts are changed test files.

3. Project gates

$ OPENCLAW_PLUGIN_SDK_BOUNDARY_ROOT_SHIMS_TIMEOUT_MS=1500000 \
    node scripts/check-changed.mjs --base upstream/main
[check:changed] lint extension changed files
[plugin-sdk boundary dts] emitted 11331 files
Found 0 warnings and 0 errors.
[check:changed] typecheck extensions / extension tests — ok
[check:changed] runtime import cycles
Import cycle check: 0 runtime value cycle(s).
check_changed_exit=0

Full log: check-changed.log. The OPENCLAW_PLUGIN_SDK_BOUNDARY_ROOT_SHIMS_TIMEOUT_MS override only raises this local host's 300 s default for the plugin-sdk boundary-dts pre-step (it exceeded 300 s on this slow box after the dependency bump); it does not change repository behavior or any check's assertions.

Risk checklist

  • No config contract change: the schema for autoJoinAllowlist is untouched, so saved configs (including user-ID entries) keep loading. No Doctor migration is required and no upgrade path changes.
  • Valid configurations are unaffected: !room, #alias:server, *, and absent allowlists keep the exact previous behavior; the alias-resolution and retry paths are unchanged.
  • Malformed prefixed entries (!, #missing-server, #ops:, #:example.org) are now reported instead of silently ignored; they never matched a room before either.
  • The warning is emitted once per registration and only for autoJoin: "allowlist"; off and always never reach it.
  • The shared predicate is now the single owner used by both the setup wizard and the runtime, so the two cannot disagree.
  • No execution-limit, routing, join-authorization, or dm.allowFrom/groupAllowFrom behavior changes. Joining a room is not acting in it; sender authorization stays with dm.allowFrom.
  • No new dependency, migration, IPC, or config surface.

Declared gaps

  • No live Matrix homeserver was used; MatrixClient is a boundary stub. Config loading uses the real Gateway loader and the invite path runs the real handler.
  • Only Linux x64 was exercised.

Rebased onto current main to resolve the merge conflict.

Fixes #160951.

Maintainer verification

Private Synapse and built-Gateway before/after, saved-config compatibility, room/alias/wildcard controls, and focused regression results: #161607 (comment)

No overlap with Pash/Sarah changes.

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: matrix Channel integration: matrix size: S labels Sep 30, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 30, 2026
@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 2:42 AM ET / 06:42 UTC (Revision 3).

ClawSweeper review

What this changes

The Matrix plugin now warns when an invite auto-join allowlist contains entries that cannot identify a room, shares the target check with setup, and updates tests and guidance.

Merge readiness

✅ Ready for maintainer review

The PR addresses the silent Matrix configuration failure without invalidating saved settings. Current main and the latest release still lack this warning. The prior alias-shape finding is fixed, and this review found no new blocking patch defect.

Priority: P2
Reviewed head: bdac4816c7330955aceada13dcde9d7e450ad230

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused patch has credible before/after Gateway-path evidence, preserves saved configuration, and resolves the prior finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied terminal trace loads a saved user-ID allowlist through the Gateway configuration loader and drives the changed Matrix invite handler through a client boundary stub; after the fix, config still loads and a default-level warning appears. No live homeserver was exercised. The schema and stored-data contract do not change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied terminal trace loads a saved user-ID allowlist through the Gateway configuration loader and drives the changed Matrix invite handler through a client boundary stub; after the fix, config still loads and a default-level warning appears. No live homeserver was exercised. The schema and stored-data contract do not change.
Evidence reviewed 7 items Introduced behavior: The pinned PR adds one registration-time warning for entries the shared predicate classifies as unable to match a room; the invite join decision remains room- and alias-based.
Prior finding resolved: The shared predicate requires both an alias local part and server name; the added table test covers empty components. This addresses the concrete finding in the previous ClawSweeper review.
Saved-config compatibility: The PR does not change the autoJoinAllowlist schema. The contributor's pinned before/after Gateway-loader transcript reports that the saved user-ID entry loads in both cases and that the changed handler emits a default-level warning afterward.
Findings None None.
Security None None.

How this fits together

The Gateway loads Matrix account settings and passes them to the Matrix plugin. The plugin checks room invites against the configured allowlist, then either joins the room or leaves the invite unanswered.

flowchart LR
A[Saved Matrix settings] --> B[Matrix account configuration]
B --> C[Invite target check]
C --> D[Configuration warning]
C --> E[Room invite handler]
E --> F[Join allowed room]
E --> G[Ignore unmatched invite]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +29, Tests +84, Docs 0. Total +113 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 34 5 +29
Tests 2 85 1 +84
Docs 2 3 3 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 122 9 +113

Review metrics

Metric Value Why it matters
Production and test lines production +34/-5, tests +85/-1 Production growth is limited to the warning and shared predicate, with focused regression coverage.
Focused test cost 105 s local wall time for 3 Matrix test files The contributor measured the affected shard and attributes most time to worker startup and transformation.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #160951
Summary: This PR is the open candidate for the linked report's silent handling of user-ID invite allowlist entries.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep saved Matrix configurations loadable while giving operators a clear warning and documented choice of room-scoped auto-join or autoJoin: "always" with sender authorization.

Do we have a high-confidence way to reproduce the issue?

Yes. Current-main source shows that user IDs cannot satisfy the invite check, and the contributor supplies a saved-config before/after trace for the warning; this reviewer did not execute contributor code.

Is this the best way to solve the issue?

Yes for the silent-failure problem: a warning gives a useful result while preserving accepted saved settings. Sender-based auto-join would be a separate policy change.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3801005f6951.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded improvement to diagnosing a Matrix invite configuration that currently fails silently.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The supplied terminal trace loads a saved user-ID allowlist through the Gateway configuration loader and drives the changed Matrix invite handler through a client boundary stub; after the fix, config still loads and a default-level warning appears. No live homeserver was exercised. The schema and stored-data contract do not change.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied terminal trace loads a saved user-ID allowlist through the Gateway configuration loader and drives the changed Matrix invite handler through a client boundary stub; after the fix, config still loads and a default-level warning appears. No live homeserver was exercised. The schema and stored-data contract do not change.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Markus Hartung: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Gustavo Madeira Santana: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-30T04:39:35.459Z sha cfab9b2ca509c21c1b28397cbfe58173260b2744 :: needs real behavior proof before merge. :: [P1] Validate the allowlist through the Gateway’s actual schema path | [P1] Preserve an upgrade path for previously accepted entries | [P2] Use the Matrix target validator for malformed prefixed entries
  • reviewed 2026-09-30T05:11:32.371Z sha bb271cd9cde052dedef6bfe6e9de6c48bf111de0 :: blocked before merge. :: [P2] Reject aliases missing a local part or server name

@xydigitLybnnnn
xydigitLybnnnn force-pushed the fix/160951-matrix-autojoin-allowlist branch from cfab9b2 to bb271cd Compare September 30, 2026 05:03
@xydigitLybnnnn

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Rewrote the fix to the recommended warn-without-blocking route and added Gateway-path proof:

  • The autoJoinAllowlist schema is no longer tightened, so saved user-ID entries keep loading (verified: loadConfig: OK before and after).
  • The inert entry is now reported at the default log level, using the shared Matrix invite-target predicate moved to target-ids (single owner with the setup wizard).
  • Proof: real Gateway config load + real registerMatrixAutoJoin run, BEFORE exit 1 / AFTER exit 0 (harness/gateway-before-fix.txt, harness/gateway-after-fix.txt); target suites 83/83; check:changed exit 0.

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 30, 2026
channels.matrix.autoJoinAllowlist accepts Matrix user IDs, but the invite
handler only matches a room ID, an alias, or "*": a user ID validated cleanly,
was persisted, and then silently ignored every invite with no output at the
default log level. Clients also mint a fresh room ID per DM, so a room-ID
allowlist cannot cover DMs either.

Keep the field schema unchanged so saved configurations still load, and warn
once at registration naming entries the room matcher can never use. The check
reuses the setup wizard's invite-target predicate, moved to the shared
target-ids owner so setup and runtime cannot drift.
@xydigitLybnnnn
xydigitLybnnnn force-pushed the fix/160951-matrix-autojoin-allowlist branch from bb271cd to bdac481 Compare September 30, 2026 06:37
@xydigitLybnnnn

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the remaining review items:

  • [P2] malformed aliases: isMatrixInviteAutoJoinTarget now requires a non-empty local part and server name, so #ops:, #:example.org, and #missing-server are all reported. Covered in the target-ids table test and the handler warning test.
  • Merge conflict: rebased onto current main (now mergeable).
  • Measured test wall time: the three changed Matrix test files run as one Vitest shard in 105 s wall locally; noted in the PR body.

Re-verified on the new base: Gateway-path BEFORE exit 1 / AFTER exit 0 (saved config still loads, warning now emitted), target suites 47/47, and check:changed exit 0 (log in the PR body).

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 30, 2026
@obviyus

obviyus commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Verified the existing head bdac4816c7330955aceada13dcde9d7e450ad230 with a built Gateway and private Synapse in isolated Docker.

  • Existing autoJoinAllowlist: ["@alice:server"] remains valid: config validate --json returned {"valid":true,"path":"/state/config.json","warnings":[]}. Gateway startup and Matrix login succeeded. Offline Doctor completed without an allowlist complaint (unrelated fresh-install setup warnings remain). No Doctor migration is needed.
  • On current main ea4e8bc83a6fc6a7555343a3fc5d257bc2be5090, Alice's real invite stayed at membership invite, without an inert-entry warning or an invite-ignored message in the default log.
  • On this PR, the invite likewise stays unanswered, but the default Gateway log records WARN: matrix: autoJoinAllowlist entries cannot match an invited room and are ignored: @alice:server. This is in the log file, not the foreground console.
  • Candidate controls: a literal room ID, homeserver-resolved alias, and * each changed the bot's membership to join. An extra attempt to repeat controls on main hit Synapse invite rate limiting after the required user-ID reproduction; candidate controls all completed.
  • The PR's two changed test files plus onboarding: candidate 47/47 pass (77.01s command wall); current main with the PR test files 35 pass / 12 fail (49.49s), including both missing-warning assertions and the missing exported predicate.
  • One real gpt-5-mini provider call from the exact-head dependency environment, reasoning low and output budget 4096, completed with MATRIX_GATE_OK.

No source changes or push were needed. Main's changes to the touched files are non-overlapping, merge-tree is clean, and the behavior above was exercised on current main.

The exact-head CI gate is successful and ClawSweeper is ready on this SHA. The four cancelled entries are orchestration, not selected test shards: Auto response, two ClawSweeper Dispatch jobs, and PR context and evidence. Auto response and PR context have successful exact-head runs; ClawSweeper subsequently completed the exact-head ready review. There are no cancelled selected test file lists to replay and no failing jobs.

@obviyus
obviyus merged commit 45a04d0 into openclaw:main Oct 7, 2026
117 of 121 checks passed
@obviyus

obviyus commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Landed. Thanks @xydigitLybnnnn! Verified against a private Synapse: on main an invite from an allowlisted user ID was silently ignored; with this the operator gets a default-level warning naming the entry, room-ID/alias/* entries still auto-join, and an existing config with a user-ID entry still loads without a migration.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…aw#161607)

Matrix invites are matched against room IDs, aliases and *, never the inviting user. A user-ID entry in channels.matrix.autoJoinAllowlist now logs a default-level warning naming it instead of silently ignoring every invite, and onboarding and docs no longer suggest user IDs. Existing configs still load unchanged.

Fixes openclaw#160951.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: autoJoinAllowlist silently ignores Matrix user IDs — schema validates them, runtime only matches room IDs

2 participants