Skip to content

[BUG] [v0.0.7] ApplyPatch cwd.join(patch path) follows POSIX absolute — can write outside workspace` #50105

Description

@fastleopard9372

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

Linux/ubuntu 22.0.4

Screenshots

Image

Steps to Reproduce

  1. Inspect resolution:

    rg -n 'full_path = cwd\.join' src/cortex-engine/src/tools/handlers/apply_patch.rs

  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingideIssues related to IDEvalidValid issue

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions