Skip to content

Commit cd33ac2

Browse files
hclhclsysgumadeiras
authored
fix(matrix): trust m.mentions.user_ids as authoritative mention source (#64796)
Merged via squash. Prepared head SHA: 59ca82e Co-authored-by: hclsys <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
1 parent d69ab71 commit cd33ac2

4 files changed

Lines changed: 57 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Docs: https://docs.openclaw.ai
88

99
### Fixes
1010

11+
- Matrix/mentions: keep room mention gating strict while accepting visible `@displayName` Matrix URI labels, so `requireMention` works for non-OpenClaw Matrix clients again. (#64796) Thanks @hclsys.
12+
1113
## 2026.4.11
1214

1315
### Changes
@@ -350,6 +352,9 @@ Docs: https://docs.openclaw.ai
350352
- Reply execution: prefer the active runtime snapshot over stale queued reply config during embedded reply and follow-up execution so SecretRef-backed reply turns stop crashing after secrets have already resolved. (#62693) Thanks @mbelinky.
351353
- Android/manual connect: allow blank port input only for TLS manual gateway endpoints so standard HTTPS Tailscale hosts default to `443` without silently changing cleartext manual connects. (#63134) Thanks @Tyler-RNG.
352354
- Matrix/agents: hide owner-only `set-profile` from embedded agent channel-action discovery so non-owner runs stop advertising profile updates they cannot execute. (#62662) Thanks @eleqtrizit.
355+
- iOS/gateway: replace string-matched connection error UI with structured gateway connection problems, preserve actionable pairing/auth failures over later generic disconnect noise, and surface reusable problem banners and details across onboarding, settings, and root status surfaces. (#62650) Thanks @ngutman.
356+
- Git/env sanitization: block additional Git repository-plumbing env variables such as `GIT_DIR`, `GIT_WORK_TREE`, `GIT_COMMON_DIR`, `GIT_INDEX_FILE`, `GIT_OBJECT_DIRECTORY`, `GIT_ALTERNATE_OBJECT_DIRECTORIES`, and `GIT_NAMESPACE` so host-run Git commands cannot be redirected to attacker-chosen repository state through inherited or request-scoped env. (#62002) Thanks @eleqtrizit.
357+
- Host exec/env sanitization: block additional request-scoped credential and config-path overrides such as `KUBECONFIG`, cloud credential-path env, `CARGO_HOME`, and `HELM_HOME` so host-run tools can no longer be redirected to attacker-chosen config or state. (#59119) Thanks @eleqtrizit.
353358

354359
## 2026.4.5
355360

‎extensions/matrix/src/matrix/monitor/handler.test.ts‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ describe("matrix monitor handler pairing account scope", () => {
180180
await handler("!room:example.org", makeEvent("$event1"));
181181
await handler("!room:example.org", makeEvent("$event2"));
182182
expect(sendMessageMatrixMock).toHaveBeenCalledTimes(1);
183-
expect(sendMessageMatrixMock.mock.calls[0]?.[1]).toContain(
184-
"Pairing request is still pending approval.",
185-
);
183+
const pairingReminder = sendMessageMatrixMock.mock.calls[0]?.[1];
184+
expect(typeof pairingReminder).toBe("string");
185+
expect(pairingReminder).toContain("Pairing request is still pending approval.");
186186

187187
await vi.advanceTimersByTimeAsync(5 * 60_000 + 1);
188188
await handler("!room:example.org", makeEvent("$event3"));
@@ -468,6 +468,30 @@ describe("matrix monitor handler pairing account scope", () => {
468468
expect(recordInboundSession).toHaveBeenCalled();
469469
});
470470

471+
it("processes room messages mentioned via @displayName in Unicode formatted_body", async () => {
472+
const recordInboundSession = vi.fn(async () => {});
473+
const { handler } = createMatrixHandlerTestHarness({
474+
isDirectMessage: false,
475+
getMemberDisplayName: async () => "欢欢",
476+
recordInboundSession,
477+
});
478+
479+
await handler(
480+
"!room:example.org",
481+
createMatrixRoomMessageEvent({
482+
eventId: "$unicode-display-name-mention",
483+
content: {
484+
msgtype: "m.text",
485+
body: "@欢欢 please reply",
486+
formatted_body: '<a href="https://matrix.to/#/@bot:example.org">@欢欢</a> please reply',
487+
"m.mentions": { user_ids: ["@bot:example.org"] },
488+
},
489+
}),
490+
);
491+
492+
expect(recordInboundSession).toHaveBeenCalled();
493+
});
494+
471495
it("does not fetch self displayName for plain-text room mentions", async () => {
472496
const getMemberDisplayName = vi.fn(async () => "Tom Servo");
473497
const { handler, recordInboundSession } = createMatrixHandlerTestHarness({

‎extensions/matrix/src/matrix/monitor/mentions.test.ts‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ describe("resolveMentions", () => {
3434
expect(result.hasExplicitMention).toBe(true);
3535
});
3636

37-
it("does not trust forged m.mentions.user_ids without a visible mention", () => {
37+
it("does not trust m.mentions.user_ids without a visible text or formatted mention", () => {
3838
const result = resolveMentions({
3939
content: {
4040
msgtype: "m.text",
41-
body: "hello",
41+
body: "please reply",
4242
"m.mentions": { user_ids: ["@bot:matrix.org"] },
4343
},
4444
userId,
45-
text: "hello",
45+
text: "please reply",
4646
mentionRegexes,
4747
});
4848
expect(result.wasMentioned).toBe(false);
@@ -209,6 +209,24 @@ describe("resolveMentions", () => {
209209
expect(result.wasMentioned).toBe(true);
210210
});
211211

212+
it("detects mention when the visible label is @displayName with Unicode text", () => {
213+
const result = resolveMentions({
214+
content: {
215+
msgtype: "m.text",
216+
body: "@欢欢 please reply",
217+
formatted_body:
218+
'<a href="https://matrix.to/#/@huanhuan:localhost">@欢欢</a> please reply',
219+
"m.mentions": { user_ids: ["@huanhuan:localhost"] },
220+
},
221+
userId: "@huanhuan:localhost",
222+
displayName: "欢欢",
223+
text: "@欢欢 please reply",
224+
mentionRegexes: [],
225+
});
226+
expect(result.wasMentioned).toBe(true);
227+
expect(result.hasExplicitMention).toBe(true);
228+
});
229+
212230
it("ignores out-of-range hexadecimal HTML entities in visible labels", () => {
213231
expect(() =>
214232
resolveMentions({

‎extensions/matrix/src/matrix/monitor/mentions.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function isVisibleMentionLabel(params: {
8181
localpart ? extractVisibleMentionText(localpart) : null,
8282
localpart ? extractVisibleMentionText(`@${localpart}`) : null,
8383
params.displayName ? extractVisibleMentionText(params.displayName) : null,
84+
params.displayName ? extractVisibleMentionText(`@${params.displayName}`) : null,
8485
].filter((value): value is string => Boolean(value));
8586
return candidates.includes(cleaned);
8687
}
@@ -163,6 +164,9 @@ export function resolveMentions(params: {
163164
mentionRegexes: params.mentionRegexes,
164165
})
165166
: false;
167+
// Matrix clients can mention users through m.mentions metadata plus a visible
168+
// Matrix URI label in formatted_body. Keep the visible-mention requirement so
169+
// hidden metadata-only mentions do not trigger the handler.
166170
const metadataBackedUserMention = Boolean(
167171
params.userId &&
168172
mentionedUsers.has(params.userId) &&

0 commit comments

Comments
 (0)