security(message-tool): validate filePath/path against sandbox root (#6398)
* security(message-tool): validate filePath/path against sandbox root * style: translate Polish comments to English for consistency
This commit is contained in:
@@ -19,6 +19,7 @@ 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";
|
||||
|
||||
@@ -252,6 +253,7 @@ type MessageToolOptions = {
|
||||
currentThreadTs?: string;
|
||||
replyToMode?: "off" | "first" | "all";
|
||||
hasRepliedRef?: { value: boolean };
|
||||
sandboxRoot?: string;
|
||||
};
|
||||
|
||||
function buildMessageToolSchema(cfg: OpenClawConfig) {
|
||||
@@ -362,6 +364,17 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
|
||||
required: true,
|
||||
}) as ChannelMessageActionName;
|
||||
|
||||
// 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;
|
||||
|
||||
Reference in New Issue
Block a user