sec(policy): add symlink boundary check to load_policy_file()#1893
Merged
sec(policy): add symlink boundary check to load_policy_file()#1893
Conversation
Canonicalize the policy file path before reading and verify it stays within the process working directory, matching the same pattern used in load_instructions(). This eliminates a TOCTOU window and prevents symlinks inside the project from pointing to files outside the root. Adds FileEscapesRoot error variant and two unit tests covering the happy path and the symlink escape rejection. Closes #1872
Both test sections coexist: symlink boundary check (this PR) and tool alias resolution (main).
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.
Summary
load_instructions())PolicyCompileError::FileEscapesRooterror variantMotivation
load_policy_file()incrates/zeph-tools/src/policy.rsopened the file via the raw path, allowing a symlink inside the project to point outside the project root.load_instructions()already performs this check; this PR brings parity.Risk: Low —
policy_fileis admin-controlled config. Defense in depth.Closes #1872
Test plan
cargo nextest run -p zeph-tools --features policy-enforcer --lib— 728 passedcargo clippy --workspace --features full -- -D warnings— cleancargo +nightly fmt --check— cleanpolicy_file_loaded_from_cwd_subdirandpolicy_file_symlink_escaping_project_root_is_rejectedpass