Skip to content

Commit ab4cb94

Browse files
authored
fix: Normalize paths in resolvePathAgainstWorkdir to prevent path traversal vulnerability (#895)
This PR fixes a potential path traversal vulnerability by ensuring all paths are properly normalized in the `resolvePathAgainstWorkdir` function. ## Changes - Added path normalization for both absolute and relative paths - Ensures normalized paths are used in all subsequent operations - Prevents potential path traversal attacks through non-normalized paths This minimal change addresses the security concern without adding unnecessary complexity, while maintaining compatibility with existing code.
1 parent 73fe138 commit ab4cb94

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

codex-cli/src/approvals.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,14 @@ export function resolvePathAgainstWorkdir(
281281
candidatePath: string,
282282
workdir: string | undefined,
283283
): string {
284-
if (path.isAbsolute(candidatePath)) {
285-
return candidatePath;
284+
// Normalize candidatePath to prevent path traversal attacks
285+
const normalizedCandidatePath = path.normalize(candidatePath);
286+
if (path.isAbsolute(normalizedCandidatePath)) {
287+
return normalizedCandidatePath;
286288
} else if (workdir != null) {
287-
return path.resolve(workdir, candidatePath);
289+
return path.resolve(workdir, normalizedCandidatePath);
288290
} else {
289-
return path.resolve(candidatePath);
291+
return path.resolve(normalizedCandidatePath);
290292
}
291293
}
292294

0 commit comments

Comments
 (0)