mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 08:37:41 +00:00
Security: harden sandboxed media handling (#9182)
* Message: enforce sandbox for media param * fix: harden sandboxed media handling (#8780) (thanks @victormier) * chore: format message action runner (#8780) (thanks @victormier) --------- Co-authored-by: Victor Mier <victormier@gmail.com>
This commit is contained in:
committed by
GitHub
parent
5e025c4ba3
commit
4434cae565
@@ -10,6 +10,7 @@ import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { OutboundSendDeps } from "./deliver.js";
|
||||
import type { MessagePollResult, MessageSendResult } from "./message.js";
|
||||
import { resolveSessionAgentId } from "../../agents/agent-scope.js";
|
||||
import { assertMediaNotDataUrl, resolveSandboxedMediaSource } from "../../agents/sandbox-paths.js";
|
||||
import {
|
||||
readNumberParam,
|
||||
readStringArrayParam,
|
||||
@@ -62,6 +63,7 @@ export type RunMessageActionParams = {
|
||||
deps?: OutboundSendDeps;
|
||||
sessionKey?: string;
|
||||
agentId?: string;
|
||||
sandboxRoot?: string;
|
||||
dryRun?: boolean;
|
||||
abortSignal?: AbortSignal;
|
||||
};
|
||||
@@ -326,6 +328,53 @@ function normalizeBase64Payload(params: { base64?: string; contentType?: string
|
||||
};
|
||||
}
|
||||
|
||||
async function normalizeSandboxMediaParams(params: {
|
||||
args: Record<string, unknown>;
|
||||
sandboxRoot?: string;
|
||||
}): Promise<void> {
|
||||
const sandboxRoot = params.sandboxRoot?.trim();
|
||||
const mediaKeys: Array<"media" | "path" | "filePath"> = ["media", "path", "filePath"];
|
||||
for (const key of mediaKeys) {
|
||||
const raw = readStringParam(params.args, key, { trim: false });
|
||||
if (!raw) {
|
||||
continue;
|
||||
}
|
||||
assertMediaNotDataUrl(raw);
|
||||
if (!sandboxRoot) {
|
||||
continue;
|
||||
}
|
||||
const normalized = await resolveSandboxedMediaSource({ media: raw, sandboxRoot });
|
||||
if (normalized !== raw) {
|
||||
params.args[key] = normalized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function normalizeSandboxMediaList(params: {
|
||||
values: string[];
|
||||
sandboxRoot?: string;
|
||||
}): Promise<string[]> {
|
||||
const sandboxRoot = params.sandboxRoot?.trim();
|
||||
const normalized: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const value of params.values) {
|
||||
const raw = value?.trim();
|
||||
if (!raw) {
|
||||
continue;
|
||||
}
|
||||
assertMediaNotDataUrl(raw);
|
||||
const resolved = sandboxRoot
|
||||
? await resolveSandboxedMediaSource({ media: raw, sandboxRoot })
|
||||
: raw;
|
||||
if (seen.has(resolved)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(resolved);
|
||||
normalized.push(resolved);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
async function hydrateSetGroupIconParams(params: {
|
||||
cfg: OpenClawConfig;
|
||||
channel: ChannelId;
|
||||
@@ -699,6 +748,14 @@ async function handleSendAction(ctx: ResolvedActionContext): Promise<MessageActi
|
||||
pushMedia(url);
|
||||
}
|
||||
pushMedia(parsed.mediaUrl);
|
||||
|
||||
const normalizedMediaUrls = await normalizeSandboxMediaList({
|
||||
values: mergedMediaUrls,
|
||||
sandboxRoot: input.sandboxRoot,
|
||||
});
|
||||
mergedMediaUrls.length = 0;
|
||||
mergedMediaUrls.push(...normalizedMediaUrls);
|
||||
|
||||
message = parsed.text;
|
||||
params.message = message;
|
||||
if (!params.replyTo && parsed.replyToId) {
|
||||
@@ -967,6 +1024,11 @@ export async function runMessageAction(
|
||||
}
|
||||
const dryRun = Boolean(input.dryRun ?? readBooleanParam(params, "dryRun"));
|
||||
|
||||
await normalizeSandboxMediaParams({
|
||||
args: params,
|
||||
sandboxRoot: input.sandboxRoot,
|
||||
});
|
||||
|
||||
await hydrateSendAttachmentParams({
|
||||
cfg,
|
||||
channel,
|
||||
|
||||
Reference in New Issue
Block a user