Repository navigation
fix(app-logic): bound remote file reads for write preview and read action - #1552
Merged
smart-ssh-coordinator[bot] merged 3 commits intoNov 24, 2026
Conversation
…tion (#1550) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
5 tasks
5 tasks
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
Blocking
crates/app-logic/src/orchestration/action_exec/tests_files_and_ledger.rs(preview_read_is_capped,read_remote_file_without_usable_stat_uses_capped_read_only): the tests do not pin the limit. Acceptance criterion 1 asks for a mock whoseread_file_cappedrecords the limit. The tests only check the call name, becauseMockSftpSessionlogsread_file_capped <path>withoutmax_bytes. I changed both production calls inremote_files.rstoread_file_capped(path, u64::MAX, …). That is an unbounded read, so/dev/zerowould exhaust memory again. Both tests still passed (cargo test -p app-logic --lib -- preview_read_is_capped read_remote_file_without_usable_stat→ 2 passed). To fix this, record themax_bytesargument (in a local mock in the test file, or in the mock's call log) and assertMAX_PREVIEW_FILE_BYTES + 1andMAX_READ_FILE_BYTES + 1. An uncappedread_filethat panics, as the criterion describes, would also be fine.docs/specs/0020-sftp-file-transfer.md:76-79(§4.1) and:302-304(known limitations): the spec now contradicts the code. §4.1 still says the 256 KB limit "wird anhand der vorab abgefragten Größe geprüft; liefert diese Abfrage keinen Wert, wird trotzdem gelesen". The known-limitations bullet says a file that grows betweenstatand the read "wird dort nicht erneut geprüft". After this PR, the read is capped and anything over the limit is refused with an error, even whenstatfails, reports 0 or is stale. The sentence the PR adds to §4.2 point 3 contradicts §4.1 in the same spec. Update §4.1 (the read stops at the limit and a larger result is refused with a message) and remove or rewrite the limitation bullet.
Non-blocking
remote_files.rs:104-106: a text file above 1 MiB is shown with the binary-file hint ("Binary file — text comparison not possible. Previous size: 1 MiB"). The size shown is the cap, not the real size. The issue allowssize_or_cap, so this is not blocking. An honest note ("larger than 1 MiB, no preview") or thestatsize would be clearer (follow-up).
Verified
- counter-proof:
git checkout origin/develop -- remote_files.rs propose.rsturnedpreview_read_is_capped,denied_write_proposal_reads_nothingandread_remote_file_without_usable_stat_uses_capped_read_onlyred. Restoring the fix turned them green again.preview_file_at_cap_still_shows_contentis a boundary test and passes both ways, as expected. Setting the limit tou64::MAXkept both cap tests green (see Blocking). (executed) - edge cases: file exactly at the cap → content preview (read + test). Cap + 1 → hint (read). Missing file /
staterror → capped read,Errbranch (test). Size-0 special file → capped read, over-limit → refused (read). File that grows afterstat→ refused by the post-read length check (read). Denied action → no SFTP access at all (test);Confirm/AutoExecstill get the preview (readpropose.rs:341-349). - callers checked:
previous_file_content_for_action(1 call site,announce_proposal) → ok.execute_read_remote_file(1 call site,execute.rs:100) → ok.ChatActionProposedPayload.previousFileSizein the frontend (ActionCard.tsx:152) → oversize goes throughBinaryFileChangeHint, consistent with the spec. (read) - tests run locally:
cargo test -q --locked -p app-logic→ 1404 + 36 passed, 0 failed (executed) - files read: 4/4 logic files (
propose.rs,remote_files.rs,tests_files_and_ledger.rs,tests_path_normalisation.rs), plus the realread_file_cappedinssh-transport/src/sftp.rsandlocal_sftp.rs(truncates atmax_byteswithtake, so cap + 1 detects overflow) - CI: all checks green except
Dependency Audit (cargo-deny / cargo-audit). That job fails on RUSTSEC-2026-0594 (cookie 0.18.2). The PR does not touchCargo.lock, and the same job is red ondevelop(38d61f74). Unrelated red job: Dependency Audit / cargo audit RUSTSEC-2026-0594. - UI: not a UI change
- data: not touched
Timing analysis
- 2 test files analysed: no timing dependency found (the responder is a
yield_nowloop, mocks are in memory, assertions run after the turn has returned)
Spec
- visible behaviour changed: the write preview of a target above 1 MiB shows the size hint instead of a diff. A denied write reads no target.
ReadRemoteFilerefuses content over 256 KB even without a usablestat, with a new error message. - spec searched:
rg -il 'preview|vorschau|binär' docs/specs/,rg -n 'Obergrenze|256|zu groß' docs/specs/0020… docs/specs/0086…; the spec covering it is 0020 §4.1, §4.2 point 3 and the known limitations - verdict: the §4.2 point 3 update is present and matches the code, but §4.1 and the limitations bullet are now wrong (blocking, update 0020)
Security checks
- Filter decision unchanged: only the preview read is gated on
Decision::Deny; the decision value and the card payload are unchanged. Only escalation, no softening. - Loosening check:
execute_read_remote_filekeeps thestatpre-check and adds a post-read check. No path reads more than before, and the error stays visible in chat (no fail-open). Preview read errors still give(None, None), as before. - Bypass attempts:
/dev/zero(size 0) → capped.statfailing on a path thatreadaccepts → capped. File growing afterstat→ refused. Symlink to a huge file →openfollows it,takecaps the read. Denied/etc/*write → no read. Very large file at cap ± 1 → correct branch. A broken cap (u64::MAX) is not caught by the tests (see Blocking). - Redaction: the preview content goes only to the UI, as before. The read action still redacts and fences before it reaches the AI context.
- Threat model: "no change – only tightens a read bound" holds.
Follow-ups
- Oversize write preview: show an honest "larger than 1 MiB" note or the real size instead of the binary-file hint with the cap as the size.
…ec 0020 (#1550) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
Author
|
Review points: (1) fixed in a2b3db2 — the mock now records |
There was a problem hiding this comment.
Review
Verdict: approved
Review level: elevated
Blocking
None.
Non-blocking
tests_files_and_ledger.rs:preview_read_is_capped: the mock'sread_filedoes not panic as criterion 1 describes. The test asserts instead that noread_file <path>call was recorded, and thatread_file_cappedreceived exactlyMAX_PREVIEW_FILE_BYTES + 1. That is equivalent in effect, and the counter-proof below shows the test goes red without the fix.
Verified
- counter-proof: I reverted
propose.rstoorigin/developand put the uncappedread_fileback in both places inremote_files.rs.preview_read_is_capped,denied_write_proposal_reads_nothingandread_remote_file_without_usable_stat_uses_capped_read_onlyeach fail without the fix and pass with it.preview_file_at_cap_still_shows_contentis a boundary test and passes either way, as expected. Fix restored withgit checkout, working tree clean. (executed:cargo test -q --locked -p app-logic --lib <name>) - the limit is asserted exactly (
capped_read_limits() == [cap + 1]), so an unboundedu64::MAXwould now fail (read: tests_files_and_ledger.rs) - edge cases (read: remote_files.rs, propose.rs, ssh-transport/src/sftp.rs):
- file exactly at the cap → content preview (test)
- cap + 1 →
(None, Some(cap))(test) /dev/zeroor astaterror → capped read, then refused when over the limit- file grows between
statand read → refused when over the limit - missing preview target →
Errpath, unchanged Confirm/AutoExecstill read the preview,Denyreads nothing
→ ok
- callers checked:
previous_file_content_for_action(1 call site,announce_proposal),execute_read_remote_file(1 call site,execute.rs) → ok. The realread_file_capped(russh) stops aftermax_bytesviatake, and the elevated wrapper forwards the limit → ok (read) - tests run locally:
cargo test -q --locked -p app-logic --lib orchestration::action_exec→ 249 passed (executed) - CI: all checks green on head 288a291 (executed:
gh pr checks 1552); Dependency Audit is green now too - files read: 5/5 logic files (full diff)
- UI: not a UI change
- data: not touched
Timing analysis
- 2 test files analysed: no timing dependency found (single task, in-memory mocks, the responder uses
yield_nowinstead of fixed waits)
Spec
- visible behaviour changed:
- the write preview reads at most 1 MiB, and a larger file gets the binary-style note
- a denied write reads nothing
ReadRemoteFilerefuses over-limit content even whenstatgives no usable size
- spec searched:
rg -il 'Vorschau|preview|WriteRemoteFile|256 KB|Diff-Ansicht' docs/specs/→ 0020 §4.1, §4.2 point 3 and the known limitations - verdict: the spec change is present and matches the code. §4.1 and the known-limitations bullet are now consistent with the capped read (previous finding 2).
- changelog fragment present (Security), English
Security checks
- The filter decision is unchanged.
announce_proposalonly readsdecisionto skip the preview read, and the card still shows the final decision. - No new path around
FilterEngine::evaluate(). The preview content goes to the UI only, not to the AI context.ReadRemoteFileredaction and fencing are unchanged. - Loosening check: every changed read is strictly tighter than before (unbounded → bounded). No branch now accepts content that was refused before: an over-limit result is an error, not a truncated success. A truncated preview is never shown as content.
- Bypass attempts:
/dev/zerowithstatsize 0statfailing- a file growing after
stat - a file exactly at the cap and at cap + 1
- an invalid-UTF-8 file under the cap
- a deny rule on
sftp-write /etc/*
→ all bounded or no read
- Threat model: no change – the PR only tightens a read bound before the decision. I accept this reason; the
threat-model-notecheck is green.
Previous findings (follow-up round only)
- tests did not check the limit passed to
read_file_capped→ fixed in a2b3db2 (the mock recordsmax_bytes, and both tests assert cap + 1) - spec 0020 §4.1 and the known-limitations bullet contradicted the code → fixed in a2b3db2
- 288a291 is a merge of
develop; the content diff against the base is unchanged apart from the above
Follow-ups
None.
smart-ssh-coordinator
Bot
deleted the
issue-1550-remote-file-preview-reads-the-target
branch
November 24, 2026 12:59
6 tasks
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.
Closes #1550
Summary
read_file_capped(1 MiB cap, +1 to detect overflow); a larger file yields(None, Some(cap))like a binary file.WriteRemoteFileno longer reads the target at all.execute_read_remote_fileusesread_file_cappedwithMAX_READ_FILE_BYTES(+1); an over-limit result is refused.Acceptance Criteria
tests_files_and_ledger.rs:preview_read_is_capped(asserts no uncappedread_file, capped call, size note);preview_file_at_cap_still_shows_content.denied_write_proposal_reads_nothing.read_remote_file_without_usable_stat_uses_capped_read_only.cargo test -p app-logicgreen locally.Tests
Counter-proof: the new tests reference the new cap and assert calls that only exist after the fix; not separately run against the reverted code.
Assumptions
Spec: updated 0020
Threat model: no change – only tightens a read bound before the decision; decision logic unchanged.
Manual test steps
None.
Follow-ups
None.
🤖 Generated with Claude Code