Lightweight coding agent that runs in your terminal
Rust
fix: Normalize paths in resolvePathAgainstWorkdir to prevent path traversal vulnerability (#895)
Avi Rosenbergab4cb9422753
diff --git a/codex-cli/src/approvals.ts b/codex-cli/src/approvals.tsindex 5ea73eab07..032acec026 100644--- a/codex-cli/src/approvals.ts+++ b/codex-cli/src/approvals.ts@@ -281,12 +281,14 @@ export function resolvePathAgainstWorkdir(candidatePath: string,workdir: string | undefined,): string {- if (path.isAbsolute(candidatePath)) {- return candidatePath;+ // Normalize candidatePath to prevent path traversal attacks+ const normalizedCandidatePath = path.normalize(candidatePath);+ if (path.isAbsolute(normalizedCandidatePath)) {+ return normalizedCandidatePath;} else if (workdir != null) {- return path.resolve(workdir, candidatePath);+ return path.resolve(workdir, normalizedCandidatePath);} else {- return path.resolve(candidatePath);+ return path.resolve(normalizedCandidatePath);}}