Repository navigation
Description
Goal
The sudo fallback for a confirmed file write never copies a file that is larger than its reported size into a backup, so a root-only endless or fast-growing file cannot fill the server disk.
Context
Follow-up of #1714 (PR #1728): the regular write bounds its backup copy by the stat size, and the SHA-256 "before" hash in the sudo fallback is bounded too (hash_old_content, crates/app-logic/src/orchestration/remote_files.rs, ~line 405-). But the backup itself in write_via_sudo_fallback (~line 544) is sudo -S cp -p <path> <backup>, unbounded. Today hash_old_content returns None both on a read error (e.g. file not readable over SFTP, legitimate for root-only files) and when the file exceeded its stat size, so the caller cannot tell the cases apart.
Requirements
hash_old_contentreports three outcomes: hash, unreadable (error), exceeded the stat size.- When the old file exceeded its stat size,
write_via_sudo_fallbackaborts with an error before runningcp; the target is untouched and no backup is created. - On a read error the behaviour stays as today (
sha256_before = None,cpstill runs). - Spec 0020 §4.3.4: replace the "sudo copy is not limited" half-sentence with the new behaviour.
Acceptance Criteria
- Mock: an old file yielding more bytes than its stat size makes the sudo fallback fail; no
sudo cpcommand is executed and the target is not written. - A read error still lets the sudo fallback run with
sha256_before = None(existing test passes). - A file that matches its stat size is copied and hashed as before.
- Relevant automated tests pass
Technical Notes
Security-adjacent (privileged command path), but the command text and the confirmation flow stay unchanged; no loosening. Pseudo files with stat size 0 (e.g. under /proc) then fail in the sudo path too, same as in the regular path. A bounded copy via head -c is the alternative (not recommended: changes the privileged command and loses cp -p attributes).
Files: crates/app-logic/src/orchestration/remote_files.rs, crates/app-logic/src/orchestration/action_exec/tests_activity.rs, docs/specs/0020-sftp-file-transfer.md
Spec impact: update 0020
Open questions
- Abort (recommended) or bounded copy with
head -c <size+1>and a size check afterwards.
Activity
smart-ssh-coder commentedon Dec 4, 2026
Needs maintainer: The issue waits for #1733, but "blocked by" could not be set. Set it on the issue (Relationships), then remove needs-maintainer: The code this issue changes (hash_old_content, bounded backup from #1714/PR #1728) exists only on release/0.8.0 and is not on develop yet; remote_files.rs on develop still hashes inline. Waiting for the back-merge of release/0.8.0 into develop (#1733).
fix(app-logic): abort the sudo write when the old file exceeds its st…
smart-ssh-coder commentedon Dec 5, 2026
Implementation ready for review. PR #1776. hash_old_content now reports hash/unreadable/exceeded; the sudo fallback aborts before sudo cp when the old file exceeds its stat size, read errors behave as before. Spec 0020 4.3.4 and a changelog fragment updated; tests added with counter-proof; CI green on PR #1776.