Skip to content

Commit ee1b147

Browse files
committed
fix(zalouser): harden inbound sender id handling
1 parent 208a9b1 commit ee1b147

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

extensions/zalouser/src/monitor.account-scope.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { OpenClawConfig, PluginRuntime, RuntimeEnv } from "openclaw/plugin-
22
import { describe, expect, it, vi } from "vitest";
33
import { __testing } from "./monitor.js";
44
import { setZalouserRuntime } from "./runtime.js";
5-
import type { ResolvedZalouserAccount, ZcaMessage } from "./types.js";
5+
import type { ResolvedZalouserAccount, ZaloInboundMessage } from "./types.js";
66

77
const sendMessageZalouserMock = vi.hoisted(() => vi.fn(async () => {}));
88

@@ -72,17 +72,16 @@ describe("zalouser monitor pairing account scoping", () => {
7272
},
7373
};
7474

75-
const message: ZcaMessage = {
75+
const message: ZaloInboundMessage = {
7676
threadId: "chat-1",
77+
isGroup: false,
78+
senderId: "attacker",
79+
senderName: "Attacker",
80+
groupName: undefined,
81+
timestampMs: Date.now(),
7782
msgId: "msg-1",
78-
type: 1,
7983
content: "hello",
80-
timestamp: Math.floor(Date.now() / 1000),
81-
metadata: {
82-
isGroup: false,
83-
fromId: "attacker",
84-
senderName: "Attacker",
85-
},
84+
raw: { source: "test" },
8685
};
8786

8887
const runtime: RuntimeEnv = {

extensions/zalouser/src/monitor.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ function logVerbose(core: ZalouserCoreRuntime, runtime: RuntimeEnv, message: str
6161
}
6262
}
6363

64-
function isSenderAllowed(senderId: string, allowFrom: string[]): boolean {
64+
function isSenderAllowed(senderId: string | undefined, allowFrom: string[]): boolean {
6565
if (allowFrom.includes("*")) {
6666
return true;
6767
}
68-
const normalizedSenderId = senderId.toLowerCase();
68+
const normalizedSenderId = senderId?.trim().toLowerCase();
69+
if (!normalizedSenderId) {
70+
return false;
71+
}
6972
return allowFrom.some((entry) => {
7073
const normalized = entry.toLowerCase().replace(/^(zalouser|zlu):/i, "");
7174
return normalized === normalizedSenderId;
@@ -133,7 +136,11 @@ async function processMessage(
133136
}
134137

135138
const isGroup = message.isGroup;
136-
const senderId = message.senderId;
139+
const senderId = message.senderId?.trim();
140+
if (!senderId) {
141+
logVerbose(core, runtime, `zalouser: drop message ${chatId} (missing senderId)`);
142+
return;
143+
}
137144
const senderName = message.senderName ?? "";
138145
const groupName = message.groupName ?? "";
139146
const chatId = message.threadId;

0 commit comments

Comments
 (0)