mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 05:32:44 +00:00
fix(security): centralize owner-only tool gating and scope maps
This commit is contained in:
@@ -5,7 +5,9 @@ import type { ImageSanitizationLimits } from "../image-sanitization.js";
|
||||
import { sanitizeToolResultImages } from "../tool-images.js";
|
||||
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
export type AnyAgentTool = AgentTool<any, unknown>;
|
||||
export type AnyAgentTool = AgentTool<any, unknown> & {
|
||||
ownerOnly?: boolean;
|
||||
};
|
||||
|
||||
export type StringParamOptions = {
|
||||
required?: boolean;
|
||||
@@ -210,10 +212,19 @@ export function jsonResult(payload: unknown): AgentToolResult<unknown> {
|
||||
};
|
||||
}
|
||||
|
||||
export function assertOwnerSender(senderIsOwner?: boolean): void {
|
||||
if (senderIsOwner === false) {
|
||||
throw new Error(OWNER_ONLY_TOOL_ERROR);
|
||||
export function wrapOwnerOnlyToolExecution(
|
||||
tool: AnyAgentTool,
|
||||
senderIsOwner: boolean,
|
||||
): AnyAgentTool {
|
||||
if (tool.ownerOnly !== true || senderIsOwner || !tool.execute) {
|
||||
return tool;
|
||||
}
|
||||
return {
|
||||
...tool,
|
||||
execute: async () => {
|
||||
throw new Error(OWNER_ONLY_TOOL_ERROR);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function imageResult(params: {
|
||||
|
||||
Reference in New Issue
Block a user