fix(F7): canonicalize paths in permission check_path (follow symlinks) - #82
Merged
Conversation
Track F-HIGH #7 from ROADMAP.md. ## Problem `resolve_absolute` (`permission/checker.rs:370-376`) joined relative paths against working_dir but never followed symlinks. A user could create: ln -s /etc/passwd ./benign-name.txt …and any deny rule on `/etc/**` would be bypassed because the pattern matcher only saw `./benign-name.txt`. Same hole for external-directory rules in `Accept` mode. ## Fix `resolve_absolute` now calls `std::fs::canonicalize` on the joined path. canonicalize() resolves symlinks AND normalizes `.` / `..` lexically — the path the rule matches is now the real target, not the link name. Three-level fallback for nonexistent paths (writes to new files need to resolve too): 1. Try `canonicalize(full_path)` — works for existing paths + symlinks. 2. If that fails (NotFound on write-to-new), try `canonicalize(parent) + basename` — catches `/safe/parent/../../etc/passwd` style attacks where the parent exists. 3. If even the parent can't canonicalize (test fixture dirs that don't exist on disk), fall back to the lexical join. Matches pre-F7 behavior so existing permission tests on not-yet-existing paths still match. ## Tests Two new tests in `permission::checker::tests`: - `resolve_absolute_follows_symlinks`: creates a tempdir with `real-secret.txt` and a `benign-name.txt` symlink to it; asserts resolve returns the real target's canonical path, not the link name. Handles macOS `/tmp -> /private/tmp` by canonicalizing the expected path too. - `resolve_absolute_handles_nonexistent_via_parent_canonicalize`: parent dir exists but the leaf doesn't; asserts the result is `canonical(parent) / leaf` — proves the second-level fallback works without breaking parent resolution. 662 pass (was 660). All build profiles clean.
allen-munsch
pushed a commit
to allen-munsch/dirge
that referenced
this pull request
Jun 3, 2026
…ks (dirge-code#82) Track F-HIGH dirge-code#7 from ROADMAP.md. ## Problem `resolve_absolute` (`permission/checker.rs:370-376`) joined relative paths against working_dir but never followed symlinks. A user could create: ln -s /etc/passwd ./benign-name.txt …and any deny rule on `/etc/**` would be bypassed because the pattern matcher only saw `./benign-name.txt`. Same hole for external-directory rules in `Accept` mode. ## Fix `resolve_absolute` now calls `std::fs::canonicalize` on the joined path. canonicalize() resolves symlinks AND normalizes `.` / `..` lexically — the path the rule matches is now the real target, not the link name. Three-level fallback for nonexistent paths (writes to new files need to resolve too): 1. Try `canonicalize(full_path)` — works for existing paths + symlinks. 2. If that fails (NotFound on write-to-new), try `canonicalize(parent) + basename` — catches `/safe/parent/../../etc/passwd` style attacks where the parent exists. 3. If even the parent can't canonicalize (test fixture dirs that don't exist on disk), fall back to the lexical join. Matches pre-F7 behavior so existing permission tests on not-yet-existing paths still match. ## Tests Two new tests in `permission::checker::tests`: - `resolve_absolute_follows_symlinks`: creates a tempdir with `real-secret.txt` and a `benign-name.txt` symlink to it; asserts resolve returns the real target's canonical path, not the link name. Handles macOS `/tmp -> /private/tmp` by canonicalizing the expected path too. - `resolve_absolute_handles_nonexistent_via_parent_canonicalize`: parent dir exists but the leaf doesn't; asserts the result is `canonical(parent) / leaf` — proves the second-level fallback works without breaking parent resolution. 662 pass (was 660). All build profiles clean. Co-authored-by: Yogthos <yogthos@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Track F-HIGH #7. Previously a symlink could bypass deny rules:
ln -s /etc/passwd benign-namematched against pattern rules asbenign-name. Nowresolve_absolutecanonicalizes (resolves symlinks + .. ) with three-level fallback for nonexistent paths. 2 new tests, 662 pass.