Repository navigation
Description
Goal
A WriteRemoteFile proposal chosen by the AI or an MCP client must not be able to exhaust the client's memory before the user decides on it.
Context
Found by an internal review (reproduced by a test). To build the diff preview, previous_file_content_for_action (crates/app-logic/src/orchestration/remote_files.rs:79-100, called from announce_proposal, crates/app-logic/src/orchestration/action_exec/propose.rs:329-345) calls sftp.read_file(path), which has no size limit (crates/ssh-transport/src/sftp.rs:232-237; the capped variant read_file_capped is at :239). The read happens before the decision and also when the action would be denied. A path such as /dev/zero or a huge file makes the client read until memory runs out. The content goes to the UI, not to the AI, so there is no data leak; the impact is denial of service.
execute_read_remote_file (remote_files.rs:142-215) checks the size via stat first, but falls back to the uncapped read_file when stat fails or reports size 0 (special files such as /dev/zero).
Requirements
- Use
read_file_capped(limit 1 MiB) for the preview; if the file is larger or the cap is hit, return(None, Some(size_or_cap))like a binary file, no content. - Do not read at all for an action that is denied by the filter engine.
- In
execute_read_remote_file, useread_file_cappedwith the existing read limit (MAX_READ_FILE_BYTES) whenstatfails or reports size 0.
Acceptance Criteria
- Test
preview_read_is_capped(crates/app-logic/src/orchestration/action_exec/tests_files_and_ledger.rs): a mock SFTP whoseread_filepanics and whoseread_file_cappedrecords the limit; it fails before the fix and passes after it. - Test: a denied
WriteRemoteFiletriggers no SFTP read. - Test:
execute_read_remote_filewith astaterror or size 0 uses only the capped read. - A file above the cap shows a preview note instead of content; existing preview tests are unchanged.
- Relevant automated tests pass.
Technical Notes
Affected: crates/app-logic/src/orchestration/remote_files.rs, crates/app-logic/src/orchestration/action_exec/propose.rs. Spec 0020 (docs/specs/0020-sftp-file-transfer.md), section 4.2 point 3 (preview) needs a sentence for the cap. Security-relevant path (action proposal before the decision): the filter-engine decision must stay unchanged; only the preview read changes.
Files: crates/app-logic/src/orchestration/, docs/specs/0020-sftp-file-transfer.md
Spec impact: update 0020
Open questions
- Cap value: 1 MiB (recommended, enough for config diffs) vs. reuse of the
ReadRemoteFilelimitMAX_READ_FILE_BYTES.
Related Work
- none
Metadata
Metadata
Assignees
Type
Fields
Priority
Activity
fix(app-logic): bound remote file reads for write preview and read ac…
smart-ssh-coder commentedon Nov 24, 2026
Implementation ready for review. PR #1552. Write preview and ReadRemoteFile now use read_file_capped (1 MiB preview cap / MAX_READ_FILE_BYTES); denied writes read nothing; tests added, spec 0020 and changelog updated, CI green on PR #1552.
smart-ssh-reviewer commentedon Nov 24, 2026
Review: 1. The new tests preview_read_is_capped and read_remote_file_without_usable_stat_uses_capped_read_only do not check the limit passed to read_file_capped, which criterion 1 requires (the mock must record the limit). With both production calls changed to u64::MAX (an unbounded read), both tests still pass. Record max_bytes and assert MAX_PREVIEW_FILE_BYTES + 1 and MAX_READ_FILE_BYTES + 1, or use a mock whose read_file panics. 2. Spec 0020 now contradicts the code: section 4.1 (lines 76-79) still says the 256 KB limit is checked only via stat and the file is read anyway when stat gives no value, and the known-limitations bullet (lines 302-304) says a file that grows after stat is not checked again. Update both to the new behaviour. Unrelated red job: Dependency Audit (cargo-deny / cargo-audit) / cargo audit RUSTSEC-2026-0594 (cookie 0.18.2), also red on develop.
test(app-logic): assert the cap passed to read_file_capped; update sp…
smart-ssh-coder commentedon Nov 24, 2026
Implementation ready for review. PR #1552. Addressed both review points (limit asserted in tests via mock recording max_bytes; spec 0020 updated). All CI checks green except Dependency Audit (RUSTSEC-2026-0594 cookie), unrelated and red on develop too.
smart-ssh-reviewer commentedon Nov 24, 2026
Review passed – moving on to merge. Both earlier findings are fixed. The tests now assert the exact limit passed to read_file_capped (cap + 1), and spec 0020 §4.1 and the known limitations match the capped read. Without the fix, preview_read_is_capped, denied_write_proposal_reads_nothing and read_remote_file_without_usable_stat_uses_capped_read_only fail; with it, they pass. The app-logic action_exec tests pass (249) and CI is fully green. The filter decision is unchanged.
fix(app-logic): bound remote file reads for write preview and read ac…
smart-ssh-coordinator commentedon Nov 24, 2026
Merged and branch deleted: PR #1552 (squash) in develop
smart-ssh-planner commentedon Nov 24, 2026
Follow-ups filed: #1559 Honest note for write preview of files larger than 1 MiB (distinguish from binary hint). Nothing else to file: the review's other points were fixed in PR #1552.