Skip to content

Commit 112211c

Browse files
committed
fix(feishu): suppress NO_REPLY silent token before Feishu API calls
Heartbeat and cron push messages without reply context can bypass the upstream normalize pipeline, leaking the internal NO_REPLY silent token to end users as visible text. Add defense-in-depth guards in feishuOutbound.sendText and sendMedia (matching the existing Slack guard) that suppress NO_REPLY before any Feishu API call. Closes #56117
1 parent 392724a commit 112211c

2 files changed

Lines changed: 79 additions & 2 deletions

File tree

‎extensions/feishu/src/outbound.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,74 @@ function resetOutboundMocks() {
4848
sendMediaFeishuMock.mockResolvedValue({ messageId: "media_msg" });
4949
}
5050

51+
describe("feishuOutbound NO_REPLY guard", () => {
52+
beforeEach(() => {
53+
resetOutboundMocks();
54+
});
55+
56+
it("suppresses NO_REPLY text before any Feishu API call", async () => {
57+
const result = await sendText({
58+
cfg: emptyConfig,
59+
to: "chat_1",
60+
text: "NO_REPLY",
61+
accountId: "main",
62+
});
63+
64+
expect(sendMessageFeishuMock).not.toHaveBeenCalled();
65+
expect(sendMarkdownCardFeishuMock).not.toHaveBeenCalled();
66+
expect(sendStructuredCardFeishuMock).not.toHaveBeenCalled();
67+
expect(sendMediaFeishuMock).not.toHaveBeenCalled();
68+
expect(result).toEqual(expect.objectContaining({ messageId: "suppressed" }));
69+
});
70+
71+
it("suppresses NO_REPLY with surrounding whitespace", async () => {
72+
const result = await sendText({
73+
cfg: emptyConfig,
74+
to: "chat_1",
75+
text: " NO_REPLY ",
76+
accountId: "main",
77+
});
78+
79+
expect(sendMessageFeishuMock).not.toHaveBeenCalled();
80+
expect(result).toEqual(expect.objectContaining({ messageId: "suppressed" }));
81+
});
82+
83+
it("does not suppress substantive text containing NO_REPLY", async () => {
84+
await sendText({
85+
cfg: emptyConfig,
86+
to: "chat_1",
87+
text: "This is not a NO_REPLY situation",
88+
accountId: "main",
89+
});
90+
91+
expect(sendMessageFeishuMock).toHaveBeenCalledWith(
92+
expect.objectContaining({
93+
text: "This is not a NO_REPLY situation",
94+
}),
95+
);
96+
});
97+
98+
it("suppresses NO_REPLY text caption in sendMedia but still sends media", async () => {
99+
await feishuOutbound.sendMedia?.({
100+
cfg: emptyConfig,
101+
to: "chat_1",
102+
text: "NO_REPLY",
103+
mediaUrl: "https://example.com/image.png",
104+
accountId: "main",
105+
});
106+
107+
// Text should be suppressed
108+
expect(sendMessageFeishuMock).not.toHaveBeenCalled();
109+
expect(sendMarkdownCardFeishuMock).not.toHaveBeenCalled();
110+
// Media should still be sent
111+
expect(sendMediaFeishuMock).toHaveBeenCalledWith(
112+
expect.objectContaining({
113+
mediaUrl: "https://example.com/image.png",
114+
}),
115+
);
116+
});
117+
});
118+
51119
describe("feishuOutbound.sendText local-image auto-convert", () => {
52120
beforeEach(() => {
53121
resetOutboundMocks();

‎extensions/feishu/src/outbound.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from "fs";
22
import path from "path";
33
import { createAttachedChannelResultAdapter } from "openclaw/plugin-sdk/channel-send-result";
4+
import { isSilentReplyText } from "openclaw/plugin-sdk/reply-runtime";
45
import { chunkTextForOutbound, type ChannelOutboundAdapter } from "../runtime-api.js";
56
import { resolveFeishuAccount } from "./accounts.js";
67
import { sendMediaFeishu } from "./media.js";
@@ -94,6 +95,14 @@ export const feishuOutbound: ChannelOutboundAdapter = {
9495
mediaLocalRoots,
9596
identity,
9697
}) => {
98+
// Defense-in-depth: suppress NO_REPLY token before any Feishu API call.
99+
// Heartbeat/cron pushes without reply context can bypass the upstream
100+
// normalize pipeline, leaking the internal silent token to end users.
101+
const trimmedText = text?.trim() ?? "";
102+
if (isSilentReplyText(trimmedText)) {
103+
return { messageId: "suppressed", chatId: "" };
104+
}
105+
97106
const replyToMessageId = resolveReplyToMessageId({ replyToId, threadId });
98107
// Scheme A compatibility shim:
99108
// when upstream accidentally returns a local image path as plain text,
@@ -156,8 +165,8 @@ export const feishuOutbound: ChannelOutboundAdapter = {
156165
threadId,
157166
}) => {
158167
const replyToMessageId = resolveReplyToMessageId({ replyToId, threadId });
159-
// Send text first if provided
160-
if (text?.trim()) {
168+
// Send text first if provided (suppress NO_REPLY silent token)
169+
if (text?.trim() && !isSilentReplyText(text.trim())) {
161170
await sendOutboundText({
162171
cfg,
163172
to,

0 commit comments

Comments
 (0)