Skip to content

Commit 83c8aa2

Browse files
committed
fix(cortex-common): fix validate_path_safe macOS symlink resolution
On macOS, temporary directories like /var/folders/... are actually symlinks to /private/var/folders/... When validate_path_safe validates a non-existent path, it would normalize (not canonicalize) the path, keeping /var/... format, but the root would be canonicalized to /private/var/... This caused the starts_with check to fail because /var/... doesn't start with /private/var/... Fix: When a non-existent path has an existing parent directory, canonicalize the parent to resolve symlinks, then join with the filename.
1 parent 9d29822 commit 83c8aa2

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

cortex-common/src/path_utils.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,27 @@ pub fn validate_path_safe(path: &Path, root: &Path) -> PathResult<PathBuf> {
231231
} else {
232232
canonical_root.join(path)
233233
};
234-
normalize_path(&absolute_path)
234+
let normalized = normalize_path(&absolute_path);
235+
236+
// If the parent directory exists, canonicalize it to resolve symlinks
237+
// (important for macOS where /var -> /private/var)
238+
if let Some(parent) = normalized.parent() {
239+
if parent.exists() {
240+
if let Ok(canonical_parent) = parent.canonicalize() {
241+
if let Some(file_name) = normalized.file_name() {
242+
canonical_parent.join(file_name)
243+
} else {
244+
normalized
245+
}
246+
} else {
247+
normalized
248+
}
249+
} else {
250+
normalized
251+
}
252+
} else {
253+
normalized
254+
}
235255
};
236256

237257
// Final validation: ensure path is within root

0 commit comments

Comments
 (0)