Skip to content

fix(hooks): preserve host checks when settings cannot be loaded - #4680

Merged
KuSh merged 2 commits into
rtk-ai:developfrom
Ehsan-hash:fix/settings-read-fail-closed
Oct 31, 2026
Merged

KuSh merged 2 commits into
rtk-ai:developfrom
Ehsan-hash:fix/settings-read-fail-closed

Conversation

@Ehsan-hash

Copy link
Copy Markdown
Contributor

Summary

  • Leave commands unchanged for Cursor and Droid when an existing permission settings file cannot be read or parsed, so rewriting cannot bypass a rule RTK failed to load.
  • Distinguish absent/empty settings from failed reads. Preserve valid rules and Gemini's existing behavior.

Fixes #4652.

Test plan

  • cargo fmt --all -- --check, standalone proxy formatting, cargo clippy --all-targets -- -D warnings, and cargo test --all (5,006 passed, 8 ignored).
  • Original-code reproduction: the new CLI tests fail for both Cursor and Droid on 6c1af5fb; they pass with this change.
  • Actual hook CLI checks with isolated synthetic settings: valid allow/deny rules, missing/empty files, malformed JSON, read errors, and all four Droid settings locations. A confirmed git diff rewrite distinguishes pass-through from an already-unrewritable command.
  • Separately inspected actual Cursor/Droid CLI responses and read/parse warnings. No command payloads were executed and no personal settings were used.

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.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working hooks security labels Oct 20, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🔴 Risk high

Summary

Fixes 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

  • Tests present
  • Breaking change
  • Docs updated

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 KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 and null still 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|droid reports 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.

@KuSh
KuSh merged commit 9b60314 into rtk-ai:develop Oct 31, 2026
15 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Oct 31, 2026
@Ehsan-hash

Copy link
Copy Markdown
Contributor Author

Thanks for the protocol checks and the Windows test fixup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hooks security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cursor, Gemini and Droid permission loaders drop an unreadable or unparseable settings file's rules

2 participants