Repository navigation
fix(hooks): refuse symlinked backup destinations - #4186
Ha1baraA11 wants to merge 1 commit into
Conversation
📊 Automated PR Analysis
SummaryFixes a symlink-planting vulnerability where backup writes for hook JSON files (e.g. .codex/hooks.json.bak) could follow a symlink at the destination and overwrite or exfiltrate files outside the project. Introduces a shared copy_backup_without_following_destination helper that opens the destination with O_NOFOLLOW (Unix) or FILE_FLAG_OPEN_REPARSE_POINT (Windows) so the check-then-write path can't be raced, and replaces all fs::copy backup call sites with it. Review Checklist
Linked issues: #4157 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
|
Thanks for this. The same fix is part of #4269 (commit "fix(init): back up without following a symlink at the .bak"), which routes every init backup through one helper on the split #4269 writes the backup to a temp file renamed over the |
Summary
Test plan
cargo fmt --all && cargo clippy --all-targets && cargo testrtk <command>output inspectedcargo fmt --all -- --checkcargo clippy --all-targets -- -D warningscargo test hooks::init::tests::test_backup_and_atomic_write -- --nocapture(3 passed)cargo test --all-targets(3,735 passed; the two pre-existing guard integration failures remain unchanged)cargo test --test guard_integration_test -- --skip git_diff_dash_dash_stat_pathspec_after_double_dash_is_not_stat_flag --skip git_log_malformed_digit_run_propagates_real_git_error(20 passed).codex/hooks.json.baksymlink: init refused the outside-resolving path, the symlink remained unchanged, and the outside file was not modified.