We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6322911 commit b132d99Copy full SHA for b132d99
1 file changed
sdk/src/tools/change-file.ts
@@ -14,6 +14,11 @@ const FileChangeSchema = z.object({
14
content: z.string(),
15
})
16
17
+function containsUpwardTraversal(dirPath: string): boolean {
18
+ const normalized = path.normalize(dirPath)
19
+ return normalized.includes('..')
20
+}
21
+
22
/**
23
* Checks if a path contains path traversal sequences that would escape the root.
24
* Uses proper path normalization to prevent traversal attacks.
@@ -31,7 +36,7 @@ export async function changeFile(params: {
31
36
}): Promise<CodebuffToolOutput<'str_replace'>> {
32
37
const { parameters, cwd, fs } = params
33
38
34
- if (containsPathTraversal(cwd)) {
39
+ if (containsUpwardTraversal(cwd)) {
35
40
throw new Error('cwd contains invalid path traversal')
41
}
42
const fileChange = FileChangeSchema.parse(parameters)
0 commit comments