Skip to content

fix(validation): accept absolute paths in validate_path_relative_to when working_dir is set - #1345

Merged
clouatre merged 3 commits into
mainfrom
fix/edit-overwrite-absolute-path-with-working-dir
Jul 27, 2026
Merged

fix(validation): accept absolute paths in validate_path_relative_to when working_dir is set#1345
clouatre merged 3 commits into
mainfrom
fix/edit-overwrite-absolute-path-with-working-dir

Conversation

@clouatre

@clouatre clouatre commented Jul 27, 2026

Copy link
Copy Markdown
Member

fix(validation): accept absolute paths in validate_path_relative_to when working_dir is set

Problem

edit_overwrite rejected absolute paths even when the caller supplied an explicit working_dir. For example, writing AGENTS.md to /Users/hugues/git/career/ while the MCP server CWD is the aptu-coder repo failed with "path is outside the working directory".

Root cause

validate_path_relative_to delegated to validate_parent_in_root for the require_exists=false branch. That function enforces canonical_parent.starts_with(root) -- correct when called from validate_path to keep paths inside the server CWD, but wrong when an explicit working_dir is provided. The containment boundary for working_dir callers is the orchestrator's responsibility, not the server's; the server's job is path resolution. The delegated call rejected any parent that did not sit inside the server CWD, ruling out all absolute paths.

Fix

Replace the validate_parent_in_root delegation in validate_path_relative_to's require_exists=false branch with minimal path resolution:

  1. Reject bare .. / . / trailing-slash paths (no file_name component).
  2. Join the path's parent to canonical_working_dir (Path::join handles absolute right-hand sides by discarding the left side, so absolute paths resolve correctly).
  3. canonicalize the parent -- resolves symlinks and requires the directory to exist.
  4. Verify the canonicalized parent is a directory, not a file.
  5. Return canonical_parent.join(file_name).

No containment check. validate_path_relative_to is a path resolver; access control is the orchestrator's job.

validate_parent_in_root is unchanged and continues to enforce CWD containment for validate_path (no working_dir).

Tests

  • test_validate_path_in_dir_traversal_to_sibling_accepted_with_working_dir: asserts that ../sibling/file is accepted when the caller provides an explicit working_dir; containment enforcement is the orchestrator's responsibility.
  • test_validate_path_in_dir_rejects_sibling_prefix_validate_path: confirms validate_path (CWD-scoped, no working_dir) still rejects paths outside the server CWD.
  • test_validate_path_relative_to_accepts_absolute_path_with_working_dir: new happy-path -- absolute path with working_dir outside the server CWD resolves correctly.

All 152 tests pass. cargo clippy -- -D warnings and cargo fmt --check clean.

…hen working_dir is set

Signed-off-by: Hugues Clouatre <hugues@linux.com>
@clouatre
clouatre marked this pull request as ready for review July 27, 2026 18:13
@aptu-dev aptu-dev Bot added the bug Something isn't working label Jul 27, 2026

@aptu-dev aptu-dev Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aptu Review

✅ Approve — This PR updates validate_path_relative_to to allow absolute paths when a working_dir is provided, resolving an issue where absolute paths were incorrectly rejected. It achieves this by bypassing validate_parent_in_root for new files and instead canonicalizing the parent directory to ensure it exists and is a valid directory.


Posted by aptu

Comment thread crates/aptu-coder/src/validation.rs
…tory errors

Signed-off-by: Hugues Clouatre <hugues@linux.com>

@aptu-dev aptu-dev Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aptu Review

✅ Approve — This PR updates validate_path_relative_to to correctly handle absolute paths when an explicit working_dir is provided. It replaces the overly restrictive validate_parent_in_root check with a direct resolution strategy that respects the operator-defined scope while maintaining security against path traversal via canonicalize.


Posted by aptu

Comment thread crates/aptu-coder/src/validation.rs Outdated
…lution

Signed-off-by: Hugues Clouatre <hugues@linux.com>

@aptu-dev aptu-dev Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aptu Review

✅ Approve — This PR updates validate_path_relative_to to correctly support absolute paths when an explicit working_dir is provided. It removes the restrictive validate_parent_in_root check for the require_exists=false case, shifting the responsibility of containment to the caller as per the MCP specification, while maintaining robust path resolution and error reporting.


Posted by aptu

Comment thread crates/aptu-coder/src/validation.rs
@clouatre
clouatre merged commit d704835 into main Jul 27, 2026
13 checks passed
@clouatre
clouatre deleted the fix/edit-overwrite-absolute-path-with-working-dir branch July 27, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant