Skip to content

Commit b132d99

Browse files
committed
Fix editing files (only check '..' for cwd)
1 parent 6322911 commit b132d99

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sdk/src/tools/change-file.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)