Skip to content

Commit 9750eb8

Browse files
pinguclaudecodex
authored andcommitted
fix(outbound): strip inbound metadata in normalizeReplyPayloadsForDelivery
Apply stripInboundMetadata() to outbound payload text during delivery normalization. Previously, AI-facing metadata blocks (Conversation info, Sender info, etc.) injected by buildInboundUserContextPrefix could leak into user-visible messages when the outbound pipeline did not call the strip function. Fixes #39847 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> Co-Authored-By: Codex (GPT-5.4) <[email protected]>
1 parent 11aff6e commit 9750eb8

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

‎src/infra/outbound/payloads.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,36 @@ describe("normalizeReplyPayloadsForDelivery", () => {
7272
},
7373
]);
7474
});
75+
76+
it("strips inbound metadata from payload text", () => {
77+
expect(
78+
normalizeReplyPayloadsForDelivery([
79+
{
80+
text: `Conversation info (untrusted metadata):
81+
\`\`\`json
82+
{"channel":"discord"}
83+
\`\`\`
84+
85+
Sender (untrusted metadata):
86+
\`\`\`json
87+
{"displayName":"Alice"}
88+
\`\`\`
89+
90+
Hello there`,
91+
},
92+
]),
93+
).toEqual([
94+
{
95+
text: "Hello there",
96+
mediaUrls: undefined,
97+
mediaUrl: undefined,
98+
replyToId: undefined,
99+
replyToCurrent: false,
100+
replyToTag: false,
101+
audioAsVoice: false,
102+
},
103+
]);
104+
});
75105
});
76106

77107
describe("normalizeOutboundPayloadsForJson", () => {

‎src/infra/outbound/payloads.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
22
import { parseReplyDirectives } from "../../auto-reply/reply/reply-directives.js";
3+
import { stripInboundMetadata } from "../../auto-reply/reply/strip-inbound-meta.js";
34
import {
45
formatBtwTextForExternalDelivery,
56
isRenderablePayload,
@@ -70,10 +71,12 @@ export function normalizeReplyPayloadsForDelivery(
7071
const next: ReplyPayload = {
7172
...payload,
7273
text:
73-
formatBtwTextForExternalDelivery({
74-
...payload,
75-
text: parsed.text ?? "",
76-
}) ?? "",
74+
stripInboundMetadata(
75+
formatBtwTextForExternalDelivery({
76+
...payload,
77+
text: parsed.text ?? "",
78+
}) ?? "",
79+
),
7780
mediaUrls: mergedMedia.length ? mergedMedia : undefined,
7881
mediaUrl: resolvedMediaUrl,
7982
replyToId: payload.replyToId ?? parsed.replyToId,

0 commit comments

Comments
 (0)