test(feishu): add mention regex injection regressions

This commit is contained in:
Peter Steinberger
2026-02-19 14:51:27 +01:00
parent 7e67ab75cc
commit 7426848913
2 changed files with 23 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ Docs: https://docs.openclaw.ai
- Scripts: update clawdock helper command support to include `docker-compose.extra.yml` where available. (#17094) Thanks @zerone0x.
- Security/iMessage: harden remote attachment SSH/SCP handling by requiring strict host-key verification, validating `channels.imessage.remoteHost` as `host`/`user@host`, and rejecting unsafe host tokens from config or auto-detection. Thanks @allsmog for reporting.
- Security/Feishu: prevent path traversal in Feishu inbound media temp-file writes by replacing key-derived temp filenames with UUID-based names. Thanks @allsmog for reporting.
- Security/Feishu: escape mention regex metacharacters in `stripBotMention` so crafted mention metadata cannot trigger regex injection or ReDoS during inbound message parsing. (#20916) Thanks @allsmog for reporting.
- LINE/Security: harden inbound media temp-file naming by using UUID-based temp paths for downloaded media instead of external message IDs. (#20792) Thanks @mbelinky.
- Security/Refactor: centralize hardened temp-file path generation for Feishu and LINE media downloads via shared `buildRandomTempFilePath` helper to reduce drift risk. (#20810) Thanks @mbelinky.
- Security/Media: harden local media ingestion against TOCTOU/symlink swap attacks by pinning reads to a single file descriptor with symlink rejection and inode/device verification in `saveMediaSource`. Thanks @dorjoos for reporting.

View File

@@ -5,6 +5,7 @@ import { parseFeishuMessageEvent } from "./bot.js";
function makeEvent(
chatType: "p2p" | "group",
mentions?: Array<{ key: string; name: string; id: { open_id?: string } }>,
text = "hello",
) {
return {
sender: {
@@ -15,7 +16,7 @@ function makeEvent(
chat_id: "oc_chat1",
chat_type: chatType,
message_type: "text",
content: JSON.stringify({ text: "hello" }),
content: JSON.stringify({ text }),
mentions,
},
};
@@ -62,6 +63,26 @@ describe("parseFeishuMessageEvent mentionedBot", () => {
expect(ctx.mentionedBot).toBe(false);
});
it("treats mention.name regex metacharacters as literals when stripping", () => {
const event = makeEvent(
"group",
[{ key: "@_bot_1", name: ".*", id: { open_id: BOT_OPEN_ID } }],
"@NotBot hello",
);
const ctx = parseFeishuMessageEvent(event as any, BOT_OPEN_ID);
expect(ctx.content).toBe("@NotBot hello");
});
it("treats mention.key regex metacharacters as literals when stripping", () => {
const event = makeEvent(
"group",
[{ key: ".*", name: "Bot", id: { open_id: BOT_OPEN_ID } }],
"hello world",
);
const ctx = parseFeishuMessageEvent(event as any, BOT_OPEN_ID);
expect(ctx.content).toBe("hello world");
});
it("returns mentionedBot=true for post message with at (no top-level mentions)", () => {
const BOT_OPEN_ID = "ou_bot_123";
const postContent = JSON.stringify({