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:
Gustavo Madeira Santana
2026-02-04 19:11:23 -05:00
committed by GitHub
parent 5e025c4ba3
commit 4434cae565
6 changed files with 278 additions and 80 deletions

View File

@@ -19,7 +19,6 @@ import { normalizeAccountId } from "../../routing/session-key.js";
import { normalizeMessageChannel } from "../../utils/message-channel.js";
import { resolveSessionAgentId } from "../agent-scope.js";
import { listChannelSupportedActions } from "../channel-tools.js";
import { assertSandboxPath } from "../sandbox-paths.js";
import { channelTargetSchema, channelTargetsSchema, stringEnum } from "../schema/typebox.js";
import { jsonResult, readNumberParam, readStringParam } from "./common.js";
@@ -422,17 +421,6 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
}
}
// Validate file paths against sandbox root to prevent host file access.
const sandboxRoot = options?.sandboxRoot;
if (sandboxRoot) {
for (const key of ["filePath", "path"] as const) {
const raw = readStringParam(params, key, { trim: false });
if (raw) {
await assertSandboxPath({ filePath: raw, cwd: sandboxRoot, root: sandboxRoot });
}
}
}
const accountId = readStringParam(params, "accountId") ?? agentAccountId;
if (accountId) {
params.accountId = accountId;
@@ -475,6 +463,7 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
agentId: options?.agentSessionKey
? resolveSessionAgentId({ sessionKey: options.agentSessionKey, config: cfg })
: undefined,
sandboxRoot: options?.sandboxRoot,
abortSignal: signal,
});