Allow commands to write to cwd with public paths

This commit is contained in:
Alex Gleason committed 2025-09-14 15:11:01 -05:00
1 parent e8203dd69f
commit c225821a44
10 files changed
+97 -64

No files matched your search

+4 -19
View File
@@ -3,7 +3,7 @@ import { z } from "zod";
import type { Tool } from "./Tool";
import type { JSRuntimeFS } from "../JSRuntime";
import { isAbsolutePath, createWriteAccessDeniedError } from "../security";
import { isAbsolutePath, isWriteAllowed, createWriteAccessDeniedError } from "../security";
interface TextEditorWriteParams {
path: string;
@@ -28,27 +28,12 @@ export class TextEditorWriteTool implements Tool<TextEditorWriteParams> {
this.cwd = cwd;
}
/**
* Check if write operations are allowed for the given absolute path
*/
private isWriteAllowed(absolutePath: string): boolean {
// Allow writes to /tmp/ and its subdirectories
if (absolutePath.startsWith('/tmp/') || absolutePath === '/tmp') {
return true;
}
// For other absolute paths, deny write access
return false;
}
async execute(args: TextEditorWriteParams): Promise<string> {
const { path, file_text } = args;
// Check for absolute paths and validate write permissions
if (isAbsolutePath(path)) {
if (!this.isWriteAllowed(path)) {
throw new Error(createWriteAccessDeniedError(path, undefined, this.cwd));
}
// Check write permissions
if (!isWriteAllowed(path, this.cwd)) {
throw new Error(createWriteAccessDeniedError(path, undefined, this.cwd));
}
if (