mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 05:37:27 +00:00
fix(zalouser): harden inbound sender id handling
This commit is contained in:
@@ -2,7 +2,7 @@ import type { OpenClawConfig, PluginRuntime, RuntimeEnv } from "openclaw/plugin-
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import { __testing } from "./monitor.js";
|
import { __testing } from "./monitor.js";
|
||||||
import { setZalouserRuntime } from "./runtime.js";
|
import { setZalouserRuntime } from "./runtime.js";
|
||||||
import type { ResolvedZalouserAccount, ZcaMessage } from "./types.js";
|
import type { ResolvedZalouserAccount, ZaloInboundMessage } from "./types.js";
|
||||||
|
|
||||||
const sendMessageZalouserMock = vi.hoisted(() => vi.fn(async () => {}));
|
const sendMessageZalouserMock = vi.hoisted(() => vi.fn(async () => {}));
|
||||||
|
|
||||||
@@ -72,17 +72,16 @@ describe("zalouser monitor pairing account scoping", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const message: ZcaMessage = {
|
const message: ZaloInboundMessage = {
|
||||||
threadId: "chat-1",
|
threadId: "chat-1",
|
||||||
|
isGroup: false,
|
||||||
|
senderId: "attacker",
|
||||||
|
senderName: "Attacker",
|
||||||
|
groupName: undefined,
|
||||||
|
timestampMs: Date.now(),
|
||||||
msgId: "msg-1",
|
msgId: "msg-1",
|
||||||
type: 1,
|
|
||||||
content: "hello",
|
content: "hello",
|
||||||
timestamp: Math.floor(Date.now() / 1000),
|
raw: { source: "test" },
|
||||||
metadata: {
|
|
||||||
isGroup: false,
|
|
||||||
fromId: "attacker",
|
|
||||||
senderName: "Attacker",
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const runtime: RuntimeEnv = {
|
const runtime: RuntimeEnv = {
|
||||||
|
|||||||
@@ -61,11 +61,14 @@ function logVerbose(core: ZalouserCoreRuntime, runtime: RuntimeEnv, message: str
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSenderAllowed(senderId: string, allowFrom: string[]): boolean {
|
function isSenderAllowed(senderId: string | undefined, allowFrom: string[]): boolean {
|
||||||
if (allowFrom.includes("*")) {
|
if (allowFrom.includes("*")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const normalizedSenderId = senderId.toLowerCase();
|
const normalizedSenderId = senderId?.trim().toLowerCase();
|
||||||
|
if (!normalizedSenderId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return allowFrom.some((entry) => {
|
return allowFrom.some((entry) => {
|
||||||
const normalized = entry.toLowerCase().replace(/^(zalouser|zlu):/i, "");
|
const normalized = entry.toLowerCase().replace(/^(zalouser|zlu):/i, "");
|
||||||
return normalized === normalizedSenderId;
|
return normalized === normalizedSenderId;
|
||||||
@@ -133,7 +136,11 @@ async function processMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isGroup = message.isGroup;
|
const isGroup = message.isGroup;
|
||||||
const senderId = message.senderId;
|
const senderId = message.senderId?.trim();
|
||||||
|
if (!senderId) {
|
||||||
|
logVerbose(core, runtime, `zalouser: drop message ${chatId} (missing senderId)`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const senderName = message.senderName ?? "";
|
const senderName = message.senderName ?? "";
|
||||||
const groupName = message.groupName ?? "";
|
const groupName = message.groupName ?? "";
|
||||||
const chatId = message.threadId;
|
const chatId = message.threadId;
|
||||||
|
|||||||
Reference in New Issue
Block a user