Project
cortex
Description
apply_file_change resolves targets as cwd.join(target_path) (apply_patch.rs). In Rust, Path::join ignores the left operand when the right operand is an absolute path. A malicious or buggy unified diff can therefore name --- /etc/critical.conf / +++ /etc/critical.conf (or any absolute path) and the tool will read/write that location regardless of cwd, with no call to resolve_and_validate_path.
Error Message
Debug Logs
System Information
Screenshots
Steps to Reproduce
-
Inspect resolution:
rg -n 'full_path = cwd\.join' src/cortex-engine/src/tools/handlers/apply_patch.rs
-
Confirm Rust semantics with a one-liner (optional):
rustc --edition 2021 -e 'fn main() { use std::path::Path; let p = Path::new("/tmp/ws").join("/etc/hosts"); println!("{}", p.display()); }'
Result: /etc/hosts (or equivalent), not under /tmp/ws.
Expected Behavior
Reject absolute paths in diff headers, or resolve relative to cwd only (strip leading /), then validate under allowed roots.
Actual Behavior
Patch application can affect arbitrary absolute paths on the host.
Additional Context
No response
Project
cortex
Description
apply_file_changeresolves targets ascwd.join(target_path)(apply_patch.rs). In Rust,Path::joinignores the left operand when the right operand is an absolute path. A malicious or buggy unified diff can therefore name--- /etc/critical.conf/+++ /etc/critical.conf(or any absolute path) and the tool will read/write that location regardless ofcwd, with no call toresolve_and_validate_path.Error Message
Debug Logs
System Information
Screenshots
Steps to Reproduce
Inspect resolution:
rg -n 'full_path = cwd\.join' src/cortex-engine/src/tools/handlers/apply_patch.rsConfirm Rust semantics with a one-liner (optional):
rustc --edition 2021 -e 'fn main() { use std::path::Path; let p = Path::new("/tmp/ws").join("/etc/hosts"); println!("{}", p.display()); }'Result:
/etc/hosts(or equivalent), not under/tmp/ws.Expected Behavior
Reject absolute paths in diff headers, or resolve relative to
cwdonly (strip leading/), then validate under allowed roots.Actual Behavior
Patch application can affect arbitrary absolute paths on the host.
Additional Context
No response