File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ const FileChangeSchema = z.object({
1414 content : z . string ( ) ,
1515} )
1616
17+ function containsUpwardTraversal ( dirPath : string ) : boolean {
18+ const normalized = path . normalize ( dirPath )
19+ return normalized . includes ( '..' )
20+ }
21+
1722/**
1823 * Checks if a path contains path traversal sequences that would escape the root.
1924 * Uses proper path normalization to prevent traversal attacks.
@@ -31,7 +36,7 @@ export async function changeFile(params: {
3136} ) : Promise < CodebuffToolOutput < 'str_replace' > > {
3237 const { parameters, cwd, fs } = params
3338
34- if ( containsPathTraversal ( cwd ) ) {
39+ if ( containsUpwardTraversal ( cwd ) ) {
3540 throw new Error ( 'cwd contains invalid path traversal' )
3641 }
3742 const fileChange = FileChangeSchema . parse ( parameters )
You can’t perform that action at this time.
0 commit comments