mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 16:34:33 +00:00
fix(auto-reply): prevent sender spoofing in group prompts
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import type { FinalizedMsgContext, MsgContext } from "../templating.js";
|
||||
import { normalizeChatType } from "../../channels/chat-type.js";
|
||||
import { resolveConversationLabel } from "../../channels/conversation-label.js";
|
||||
import { formatInboundBodyWithSenderMeta } from "./inbound-sender-meta.js";
|
||||
import { normalizeInboundTextNewlines } from "./inbound-text.js";
|
||||
|
||||
export type FinalizeInboundContextOptions = {
|
||||
@@ -45,7 +44,11 @@ export function finalizeInboundContext<T extends Record<string, unknown>>(
|
||||
|
||||
const bodyForAgentSource = opts.forceBodyForAgent
|
||||
? normalized.Body
|
||||
: (normalized.BodyForAgent ?? normalized.Body);
|
||||
: (normalized.BodyForAgent ??
|
||||
// Prefer "clean" text over legacy envelope-shaped Body when upstream forgets to set BodyForAgent.
|
||||
normalized.CommandBody ??
|
||||
normalized.RawBody ??
|
||||
normalized.Body);
|
||||
normalized.BodyForAgent = normalizeInboundTextNewlines(bodyForAgentSource);
|
||||
|
||||
const bodyForCommandsSource = opts.forceBodyForCommands
|
||||
@@ -66,14 +69,6 @@ export function finalizeInboundContext<T extends Record<string, unknown>>(
|
||||
normalized.ConversationLabel = explicitLabel;
|
||||
}
|
||||
|
||||
// Ensure group/channel messages retain a sender meta line even when the body is a
|
||||
// structured envelope (e.g. "[Signal ...] Alice: hi").
|
||||
normalized.Body = formatInboundBodyWithSenderMeta({ ctx: normalized, body: normalized.Body });
|
||||
normalized.BodyForAgent = formatInboundBodyWithSenderMeta({
|
||||
ctx: normalized,
|
||||
body: normalized.BodyForAgent,
|
||||
});
|
||||
|
||||
// Always set. Default-deny when upstream forgets to populate it.
|
||||
normalized.CommandAuthorized = normalized.CommandAuthorized === true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user