mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Allow commands to write to cwd with public paths
This commit is contained in:
10 files changed
+97
-64
No files matched your search
@@ -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 (
|
||||
|
||||
Reference in new issue
Block a user