Repository navigation
Approval prompt: bound Steps: lines (and every prompt line) so a long argument cannot push [y/N] off-screen - #93
cuihtlauac wants to merge 6 commits into
Conversation
cuihtlauac
left a comment
There was a problem hiding this comment.
🤖 Code review (Fable) — round 1
Verdict: approve-with-nits
Reviewed the whole diff of PR #93 against the 🤖 Approved plan (Claude) — final comment on #85. Independently re-ran on the branch: cargo clippy --all-targets --all-features -- -D warnings (clean), cargo test --lib tui:: (34 passed, the 6 new unit tests and the new property included), cargo test --test pty_ui_golden (4 passed). The diff adds exactly two golden files (long-argument.{plain,color}.txt); the 10 existing goldens are untouched. The cargo fmt --check statement is accurate: the branch shows rustfmt diffs across tests/common/pty.rs, src/protocol.rs, src/server.rs, src/executor.rs, src/mcp.rs and others, so the repo is not rustfmt-formatted and nothing was reformatted here. Kani is not needed (src/proofs.rs untouched, no proved function changed); the PR says so explicitly.
The implementation follows the plan point by point: split_at_chars is the single truncation rule behind truncate_for_display and clip; clip_styled copies CSI escapes at zero width, writes reset before the marker, is byte-identical when the line fits, and the hidden count is in visible chars (P7); Steps: lines are clipped text+note with the gutter and indent outside the budget; the Resolves: block clips the name before the dedup key and the pad width, caps at 32 with the … N more binaries hidden marker (P9), and the single-line form branches on the unclipped strings; the metadata lines moved into writer-generic write_request_meta/write_env_line with the same bytes for short values (pinned by the literal expectation in test 6); Env: uses clip(…, MAX_DISPLAY_CMD_CHARS) (P5). steps_shell_text and command_summary are untouched, and the two bash-oracle properties still pass.
Deviations from plan — all accepted
- Test 4(a), the
idrow width. Correct reading of the plan: step 3 pads to the widest clipped name (160 + marker), so "under 80 chars" was never achievable. The replacement assertion (idrow ≤MAX_DISPLAY_LINE_CHARS + MARKER_MAX + 64) still proves the plan's intent, that the 2 009-char name does not set the width. STEPS_BOUNDindent term. Verified againstlay_scope(src/tui.rs:263-275): acd/exportscope isGroup { Chain [ head, Group(body) ] }, so each plan level adds up to two nesting levels.2·(2·MAX_PLAN_DEPTH+3)is a sound constant; the plan's2·(MAX_PLAN_DEPTH+1)was not.lengthenpass instead of a generator variant. Good choice:random_anyis unchanged, so the random sequences of the two existing properties are unchanged, and the pass still produces the three-stringResolves:rows the plan wanted (1 in 8 resolvable longargv[0]).- Test 6 also lengthens
hostandversion. Strictly more coverage, no cost.
Findings
Should-fix
-
C2 —
src/tui.rs:488anddocs/assurance-case.md:116. The P7 note onclip_styledsays the clipped tail of aSteps:line "may hold the chain operator or a group's(opener". It may also hold a redirection suffix (> path,2>&1,< path) and the group closer)with its redirection:steps_emitjoinsredirinto the leaf text (src/tui.rs:927) and appendsclose = join_suffix(")", redir)to the group's last line (:962) beforewrite_stepsclips the text (:900). Add redirections to that doc comment and one sentence to the Sn4.3 residual ("a long argument can push the line's redirection, operator or parenthesis into the hidden tail;Command:still carries them under 1024 chars"), with a pointer to the follow-up issue from C1. Doc-only; no code change. -
C3 — PR body, "Follow-ups". The plan's "Out of scope (follow-ups to file, not done here)" names three items to file:
src/gui.rsformat_prompt_textunbounded and plan-blind; a total prompt-height budget plus column-width (wide glyphs, tabs) counting;display_bannerprintingcommand_summaryuntruncated. The PR lists them as "not filed by this PR". Per the Phase 0 rules, the author opens the issues (Part of #89, linking the plan comment) and lists the numbers in the PR. One combined "prompt bounds, remaining paths" issue is fine if that reads better; C1 below can go in with it or on its own.
Follow-up
- C1 —
src/tui.rs:900,:927,:962. A redirection can disappear into aSteps:line's hidden tail. Scenario: a privileged{"op":"redirect","stream":"stdout","target":{"file":"/etc/sudoers"},"body":{"op":"exec","argv":["echo","A"×1100]}}.Steps:line 0 issudo echo AAAA…… [N more chars hidden]with> /etc/sudoersin the cut tail;Command:is also cut at 1024 chars before the redirection;Resolves:shows onlyecho. No prompt line names the target file, although both markers say text is hidden. This is the F3 trade-off the plan accepts (operators deny anything with a marker), andCommand:already behaved this way, so it is not a regression against the plan's intent. A better clip policy would keep the structural suffix (operator,(/), redirections) out of the budget and clip only the command text, or clip each argv word separately; that changes theStepLineshape and the prefix-fidelity property, and belongs with the Phase 1 render-from-Compiledwork in #89. File it as its own issue or fold it into the C3 batch.
Nit
- C4 —
src/tui.rs:2325.long_echo_path(reps)is documented as "2 009 bytes long", which holds only forreps = 1_000; the property calls it withk < 1_500. Say "/+./×reps +bin/echo; 2 009 bytes at 1 000, under PATH_MAX" when next touching the line.
Nits from the plan review
P4, P5, P7, P8 and P9 were followed as described in the PR; P6 is correctly left to #90. No disagreement.
Manual test
The PR's "Manual test before merge" matches the plan's. One addition worth doing while at it: after step 3, press nothing and let the 60 s timeout expire once, to confirm the clipped prompt does not change the timeout/deny path (→ Timeout, client reports the timeout).
Only the Command: line was length-bounded (G4.3 / F3). A privileged exec of a 900 KB argument printed it whole on Steps: line 0 and pushed the [y/N] question off-screen; Resolves: names and paths and the metadata fields were unbounded too. Clip each Steps: line to 160 visible chars (clip_styled skips the daemon's own colour escapes and resets before the marker), each Resolves: name and path to 160, each metadata field to 256, the Env: line to 1024, and the Resolves: block to 32 entries, each with an explicit hidden-chars marker. truncate_for_display keeps its output and shares split_at_chars with clip. The metadata and Env: lines move into writer-generic helpers so they are unit-testable; prompt_tty writes the same bytes for short values. steps_shell_text and command_summary are unchanged. Tests: clip unit tests, Steps:/Resolves:/metadata bounds, and the property prop_prompt_lines_are_bounded_and_prefix_faithful. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
Add the long-argument UI plan (a 600-char argument, privileged) with its two goldens: Command: shows it whole, Steps: line 0 is clipped with the marker. The ten existing goldens are byte-identical. huge_argument_prompt_is_bounded sends a 900 KB argument through a real daemon on a pty and checks that every prompt line is bounded, the block is under 16 KiB, the question is the last line, and a denial runs nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
The clip_styled doc comment and the Sn4.3 residual now name redirections and the ) closer alongside the chain operator and ( opener, and point at the follow-up issues #97 (structure outside the budget) and #98 (height and column width). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
C4: long_echo_path doc gives the length as a function of reps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
8601f50 to
41c78c0
Compare
Summary
Fixes #85. Part of #89 (Phase 0).
Only the
Command:line of the approval prompt was length-bounded (G4.3 / F3). A privilegedexec ["echo", <900 KB>]printed the whole argument onSteps:line 0 and pushed the[y/N]question off-screen. TheResolves:block and line (a long absoluteargv[0], up to 256 entries) and the metadata lines were unbounded too.This PR implements the approved plan (the
🤖 Approved plan (Claude) — finalcomment on #85). It changes the display only: validation, execution,Responseand the audit log do not change.src/tui.rs: new constantsMAX_DISPLAY_LINE_CHARS(160),MAX_DISPLAY_FIELD_CHARS(256) andMAX_DISPLAY_RESOLVES(32), and new helperssplit_at_chars,clipandclip_styled.clip_styledcounts the daemon's own CSI escapes as zero width, writesresetbefore the marker, and is byte-identical when the line fits.truncate_for_displaykeeps its exact output and now sits onsplit_at_chars.Steps:lines (text plus# note) are clipped to 160 visible chars. The gutter and indent are outside the budget.Resolves:block: the name is clipped before the dedup key and the pad width. Paths are clipped inresolve_detail, including the opaque andcanonicalize failedarms. The block is capped at 32 entries, followed by… N more binaries hidden.Resolves:single line: branches are chosen on the unclipped strings, and the strings are shown clipped.From:,Requester:,Client:,Time:,ID:,Reason:and the session name in thealine are clipped to 256. The lines fromClient:throughCommand:move towrite_request_meta, andEnv:moves towrite_env_line. Both are writer-generic, so they can be unit-tested. For short valuesprompt_ttywrites the same bytes as before.steps_shell_textandcommand_summarydo not change. The bash-oracle properties still check the full texts.docs/security-audit.md, along-argumentrow in thedocs/testing.mdUI table, a changelog entry, andDone: #85.inbacklog.md. The changelog and backlog edits only add lines.Test evidence
cargo clippy --all-targets --all-features -- -D warnings(the CI command): clean.cargo test --no-fail-fast: all suites pass. Lib: 118 passed, including 6 newtuitests.pty_ui_golden: 4 passed.concurrency::burst_connections_above_cap_get_busy_responsefailed once. This is the known flaky burst test. It passed when the whole suite was run again (13/13), and this PR does not touch that code.src/tui.rs):clip_bounds_and_marksclip_styled_ignores_escapes_and_resets(includes the tab case)steps_line_is_bounded_for_huge_argumentresolves_block_bounds_long_names_and_countresolves_line_bounds_long_absolute_pathmeta_and_env_lines_are_boundedprop_prompt_lines_are_bounded_and_prefix_faithful, 300 iterations, both styles.clip_styledcall inwrite_stepsand the property failed at once. I then restored it.huge_argument_prompt_is_bounded. It sends a 900 KB argument and checks that every line is ≤ 1152 visible chars, the block is under 16 KiB, the question is the last line, the status isDenied, and the shim log is empty.UPDATE_GOLDEN=1 cargo test --test pty_ui_goldenonly to createlong-argument.{plain,color}.txt. The 10 existing golden files are byte-identical:git statusshowed no change to them after the regeneration.cargo fmt --check: it fails onorigin/mainalready, across most files (the repo is not rustfmt-formatted, and CI does not run it). I did not reformat anything.src/proofs.rsis not touched, and none of the functions it proves changed (it proves notuifunction).cargo-kani0.67.0 is installed.Deviations from plan
idrow width. The plan asked that the shortidrow stay under 80 chars. That cannot hold together with the plan's own step 3: the pad width is the maximum of the clipped names, soidis padded to about 185 chars (160 + marker). The test asserts what the plan intends instead: the padding follows the clipped name, not the 2 009-char one. The row is ≤MAX_DISPLAY_LINE_CHARS + MARKER_MAX + 64.STEPS_BOUNDindent term (test-only constant). The plan gave the indent as2·(MAX_PLAN_DEPTH+1). Acd/exportscope (( cd D && ( body ) )) adds two parenthesis levels per plan level, so the bound used is2·(2·MAX_PLAN_DEPTH+3). It is still a constant.lengthenpass runs over the plans thatrandom_anyproduces. It makes an argv element or acd/redirect/stdin path 0..3 000 chars long (1 in 4), and sets a resolvable longargv[0]"/" + "./"×k + "bin/echo"(1 in 8,k< 1 500). This leavesrandom_any, and so the random sequences of the two existing properties, unchanged.reason,sessionandrequester, the test also makeshostandversion10 000 chars long, so that every clipped metadata field is exercised.Nits
Plan review (#85 (comment)):
backlog.mdgets a separateDone: #85.line after the Phase 0 paragraph instead of an edit to the shared prose line.Env:usesclip(&joined, MAX_DISPLAY_CMD_CHARS), so it no longer says "full command not shown".clip_styleddoc comment says that the hidden count is in visible chars (escapes excluded), and that the clipped tail of aSteps:line may hold the chain operator, a group's(or), or a redirection (the last two added for C2).0gutter before it checkssudo echo AAAA, and it runs under both styles.Resolves:cap marker is… N more binaries hidden, without the "see Steps:/Command:" hint.Code review:
chore: review nits. Thelong_echo_pathdoc gives the length as2 * reps + 9bytes (2 009 forreps = 1_000); the helper is new in this PR.Follow-ups
⚠ invalid plan: {e}arm can embed an unbounded env key (plan nit P6, pre-filed).(/)in the clipped tail (code review C1).src/gui.rsformat_prompt_textis unbounded and does not render plans; no total prompt-height budget, and widths counted in chars rather than columns;display_banneris unbounded.Review
docs: clipped tail can hide redirections and group closers (#85). Theclip_styleddoc comment and the Sn4.3 residual now name redirections and the)closer, and point at Prompt clip can hide a redirection target or group closer in the clipped tail #97 and Prompt bounds beyond #85: GUI dialog text, total height and column width, display_banner #98.cargo clippy --all-targets --all-features -- -D warningsclean;cargo test --no-fail-fastall suites pass on rerun (the first run hit the known flakyconcurrency::burst_connections_above_cap_get_busy_responseonce; the full rerun and theconcurrencysuite alone, 13/13, pass). The last two commits change only comments and docs.Manual test before merge
Run this with your own live daemon, built from this branch:
docs/testing.md:cargo build --release, then runtarget/release/sudo-proxy(the same flags you normally use).Command:ends with… [198986 more chars hidden — full command not shown].Steps:line 0 reads0 sudo echo AAAA…and ends with… [199850 more chars hidden]in bold, with the light-red colour reset before the marker (no colour bleed).Execute as root? [y/N]is visible with theCommand:line still on screen.n. The client reportsdenied.NO_COLOR=1set in the daemon's environment. The same markers should appear, with no escape codes.🤖 Generated with Claude Code