mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:38:27 +00:00
fix(security): harden untrusted web tool transcripts
This commit is contained in:
@@ -322,6 +322,25 @@ export function applyGoogleTurnOrderingFix(params: {
|
||||
return { messages: sanitized, didPrepend };
|
||||
}
|
||||
|
||||
function stripToolResultDetails(messages: AgentMessage[]): AgentMessage[] {
|
||||
let touched = false;
|
||||
const out: AgentMessage[] = [];
|
||||
for (const msg of messages) {
|
||||
if (!msg || typeof msg !== "object" || (msg as { role?: unknown }).role !== "toolResult") {
|
||||
out.push(msg);
|
||||
continue;
|
||||
}
|
||||
if (!("details" in msg)) {
|
||||
out.push(msg);
|
||||
continue;
|
||||
}
|
||||
const { details: _details, ...rest } = msg as unknown as Record<string, unknown>;
|
||||
touched = true;
|
||||
out.push(rest as unknown as AgentMessage);
|
||||
}
|
||||
return touched ? out : messages;
|
||||
}
|
||||
|
||||
export async function sanitizeSessionHistory(params: {
|
||||
messages: AgentMessage[];
|
||||
modelApi?: string | null;
|
||||
@@ -353,6 +372,7 @@ export async function sanitizeSessionHistory(params: {
|
||||
const repairedTools = policy.repairToolUseResultPairing
|
||||
? sanitizeToolUseResultPairing(sanitizedToolCalls)
|
||||
: sanitizedToolCalls;
|
||||
const sanitizedToolResults = stripToolResultDetails(repairedTools);
|
||||
|
||||
const isOpenAIResponsesApi =
|
||||
params.modelApi === "openai-responses" || params.modelApi === "openai-codex-responses";
|
||||
@@ -368,8 +388,8 @@ export async function sanitizeSessionHistory(params: {
|
||||
: false;
|
||||
const sanitizedOpenAI =
|
||||
isOpenAIResponsesApi && modelChanged
|
||||
? downgradeOpenAIReasoningBlocks(repairedTools)
|
||||
: repairedTools;
|
||||
? downgradeOpenAIReasoningBlocks(sanitizedToolResults)
|
||||
: sanitizedToolResults;
|
||||
|
||||
if (hasSnapshot && (!priorSnapshot || modelChanged)) {
|
||||
appendModelSnapshot(params.sessionManager, {
|
||||
|
||||
Reference in New Issue
Block a user