@@ -44,7 +44,10 @@ export const EditTool = Tool.define("edit", {
4444 const filePath = path . isAbsolute ( params . filePath ) ? params . filePath : path . join ( Instance . directory , params . filePath )
4545 if ( ! Filesystem . contains ( Instance . directory , filePath ) ) {
4646 const parentDir = path . dirname ( filePath )
47- if ( agent . permission . external_directory === "ask" ) {
47+ // Secure default: only allow if explicitly set to "allow" or "ask"
48+ if ( agent . permission . external_directory === "allow" ) {
49+ // Explicitly allowed, proceed
50+ } else if ( agent . permission . external_directory === "ask" ) {
4851 await Permission . ask ( {
4952 type : "external_directory" ,
5053 pattern : parentDir ,
@@ -57,6 +60,9 @@ export const EditTool = Tool.define("edit", {
5760 parentDir,
5861 } ,
5962 } )
63+ } else {
64+ // Default deny for "deny", undefined, null, or any other value
65+ throw new Error ( `Permission denied: Cannot edit file outside working directory: ${ filePath } ` )
6066 }
6167 }
6268
@@ -67,7 +73,10 @@ export const EditTool = Tool.define("edit", {
6773 if ( params . oldString === "" ) {
6874 contentNew = params . newString
6975 diff = trimDiff ( createTwoFilesPatch ( filePath , filePath , contentOld , contentNew ) )
70- if ( agent . permission . edit === "ask" ) {
76+ // Secure default: only allow if explicitly set to "allow" or "ask"
77+ if ( agent . permission . edit === "allow" ) {
78+ // Explicitly allowed, proceed
79+ } else if ( agent . permission . edit === "ask" ) {
7180 await Permission . ask ( {
7281 type : "edit" ,
7382 sessionID : ctx . sessionID ,
@@ -79,6 +88,9 @@ export const EditTool = Tool.define("edit", {
7988 diff,
8089 } ,
8190 } )
91+ } else {
92+ // Default deny for "deny", undefined, null, or any other value
93+ throw new Error ( `Permission denied: Cannot edit file: ${ filePath } ` )
8294 }
8395 await Bun . write ( filePath , params . newString )
8496 await Bus . publish ( File . Event . Edited , {
@@ -98,7 +110,10 @@ export const EditTool = Tool.define("edit", {
98110 diff = trimDiff (
99111 createTwoFilesPatch ( filePath , filePath , normalizeLineEndings ( contentOld ) , normalizeLineEndings ( contentNew ) ) ,
100112 )
101- if ( agent . permission . edit === "ask" ) {
113+ // Secure default: only allow if explicitly set to "allow" or "ask"
114+ if ( agent . permission . edit === "allow" ) {
115+ // Explicitly allowed, proceed
116+ } else if ( agent . permission . edit === "ask" ) {
102117 await Permission . ask ( {
103118 type : "edit" ,
104119 sessionID : ctx . sessionID ,
@@ -110,6 +125,9 @@ export const EditTool = Tool.define("edit", {
110125 diff,
111126 } ,
112127 } )
128+ } else {
129+ // Default deny for "deny", undefined, null, or any other value
130+ throw new Error ( `Permission denied: Cannot edit file: ${ filePath } ` )
113131 }
114132
115133 await file . write ( contentNew )
0 commit comments