Repository navigation
fix(hooks): preserve host checks when settings cannot be loaded - #4680
Conversation
📊 Automated PR Analysis
SummaryFixes a fail-open bug in RTK's hook permission loading: when a Cursor or Droid settings file exists but fails to be read or parsed, the code now fails closed (denies all commands) instead of silently treating the error as 'no rules'. Also distinguishes missing/empty settings files from read/parse errors, and preserves existing behavior for Gemini. Review Checklist
Linked issues: #4652 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Cursor's settings live under the home directory, which rtk resolves with dirs::home_dir. On Windows that is the Known Folder API, so the HOME the sandbox sets never reaches the hook and the test read the runner's own profile instead: windows-latest got "ask" where the valid sandbox file grants "allow". The Droid test keeps the shared reader covered on Windows through FACTORY_HOME_OVERRIDE. Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Round 1 — APPROVED, follow-ups filed
Claim: when an existing Cursor or Droid permission settings file cannot be read or parsed, the hook leaves the command unchanged so the host applies its own checks; missing and empty files, valid rules and Gemini's output stay as they were.
Scope: accept (round 1, frozen)
Ran: rtk hook cursor / rtk hook droid / rtk hook gemini and rtk hook check --agent cursor|droid on the merge-base 6c1af5fbc, the head eaee169b6 and the head merged onto develop 3467fb24c, 368 rows per binary: 15 settings-file states (valid, missing, empty, whitespace, BOM-only, BOM + valid, trailing comma, chmod 000, directory, non-UTF-8, parent is a file, symlink loop, dangling symlink, symlink to a valid file, null) × 4 commands for Cursor and for each of the four Droid scopes, a valid user scope next to a broken project scope, Gemini global and project as a control. Head and merge identical on every row. Invariants: non-default targets (all four Droid scopes), split streams (stdout and stderr compared separately), every decision (step aside, ask, allow, rewrite each reached). No filter, so no savings figure.
Pins: 10 decisions, 10 mutated, 0 survived.
Matrix: executed this round; pin check: executed this round
CI @eaee169b6: test (windows-latest) and test (windows-latest, x86_64-pc-windows-gnu) failed on cursor_settings_keep_missing_and_empty_behavior_but_step_aside_on_failures (tests/hook_config_io_test.rs:233, "ask" vs "allow"); everything else green. Fixed by the fixup below; @4948987b2: all green.
Blocks merge
None.
Filed as follow-ups
- #4878 Gemini hook: an unreadable global settings file trusts the workspace and applies its allow rules — pre-existing (same code in v1.0.1), not changed by this PR; it corrects #4652's "Gemini is not unsafe", which this PR closes.
- #4651 — BOM-only settings file and a parent path that is a file now also make the Cursor and Droid hooks step aside, through the same classification in
read_json; absorbed by the existing issue, comment added with the rows.
Checked and correct — no need to re-verify
- Cursor and all four Droid scopes: trailing comma,
chmod 000, directory, non-UTF-8 and symlink loop step aside ({}/ no output) with a read or parse warning; valid deny still steps aside, valid allow still allows, missing, empty, whitespace, dangling symlink andnullstill rewrite. - One broken Droid scope next to a valid one steps aside for every command, not only the denied ones.
- Gemini stdout byte-identical on all 36 rows; the only change is the warning (one fewer on an empty file, a read warning on an unreadable one).
rtk hook check --agent cursor|droidreports the same decision the hook takes.- Merges cleanly with develop and with #4458; the fish-wrap deny attestation on develop reads Claude Code rules only.
- Mutations on
read_json(NotFound, other read errors, empty and whitespace-only files, parse errors), Cursor's error arm (no rules, allow-all) and Droid's (error ignored, fail closed only when no scope parsed, ask instead of deny) are each killed by the two new tests.
Next
Fixup 4948987b2 pushed, code-reviewed: it puts #[cfg(unix)] on the Cursor test and its two Cursor-only helpers. rtk finds Cursor's settings through dirs::home_dir, which on Windows uses the Known Folder API, so the sandbox's HOME never reached the hook there (same gate and reason as tests/antigravity_hook_test.rs). The Droid test still covers read_json on Windows through FACTORY_HOME_OVERRIDE. CI is green on it — approving.
Threads: 0 open.
|
Thanks for the protocol checks and the Windows test fixup. |
Summary
Fixes #4652.
Test plan
cargo fmt --all -- --check, standalone proxy formatting,cargo clippy --all-targets -- -D warnings, andcargo test --all(5,006 passed, 8 ignored).6c1af5fb; they pass with this change.git diffrewrite distinguishes pass-through from an already-unrewritable command.Prepared with AI assistance and independently reviewed. Local checks cover RTK's hook protocol; they do not claim a live Cursor or Droid permission decision. This hook change still needs the repository's two maintainer reviews.