← Back to Pull requests

set --secret: ask for a typed secret with echo off #3569

Closed
unknown closed this pull request without merging on Oct 29, 2026 04:25 UTC
View on GitHub
unknown unknown commented on Oct 29, 2026 03:16 UTC
Author

Closes #3414

Root cause

ployz set PATH --secret read stdin to EOF whatever stdin was. At a terminal that meant no prompt, the terminal's echo still on, and a wait until Ctrl-D. The typed secret showed on screen and stayed in scrollback.

The hidden prompt that recover and server enroll already use (ui::secret, which wraps dialoguer Password) couldn't simply be reused. console's read_secure turns off only ECHO, and while_prompting makes SIGINT a no-op. So Ctrl-C was swallowed, and read_line restarted after the EINTR. The prompt couldn't be cancelled, and Ctrl-D asked again. That bug is on main today for recover and server enroll.

Fix

  • set --secret (handlers/config.rs, read_secret):

  • - stdin is a terminal: asks Value for PATH: through ui::secret.
    - stdin is a terminal but the run can't prompt (--json, CI, TERM=dumb, stderr not a terminal): refuses with a usage error that says why and shows how to pipe the value. It never reads with echo on.
    - stdin is piped: no change. It reads to EOF, strips one trailing newline, keeps the 32 MiB bound, and keeps the same errors and codes.
  • ui::secret (ui/prompt.rs): it now reads with its own rustix termios reader, with no new dependency or feature. The reader turns off ECHO, ICANON, ISIG and IEXTEN.

  • - Keys: Ctrl-C (anywhere, even inside an unfinished paste) and Ctrl-D on an empty line cancel ("Cancelled. …", exit 130). Ctrl-D after some text ends the line, as it did on main. An empty line asks again, as Password did. Backspace (UTF-8 aware), Ctrl-U and Ctrl-W edit the line.
    - Pastes: bracketed paste (ESC[?2004h) is on while the prompt reads, so a paste is read to its ESC[201~ end marker however slowly it arrives. A paste with anything after a newline is refused. For a terminal that doesn't bracket pastes, after Enter it also reads on, echo still off, until nothing arrives for 200 ms. If anything other than line endings came, the paste held more than one line, and it is refused (exit 2) rather than cut to its first line. The termios restore uses TCSAFLUSH, so no part of the paste reaches the shell.

    No message on any path contains the value.

    Behaviour change

  • set --secret at a terminal now prompts Value for PATH: with echo off and takes one line. Before, it read the echoed input until Ctrl-D. A value of several lines must be piped, and a multi-line paste at the prompt is refused.

  • set --secret with a terminal on stdin, in a run that can't prompt (--json, CI, TERM=dumb, stderr redirected), now exits 2 with a message to pipe the value.

  • Ctrl-C now cancels the hidden prompts of set --secret, recover and server enroll (exit 130). Before, it was ignored.

  • A multi-line paste into any of those prompts is refused. Before, recover and enroll silently kept the first line.

  • Piped input, JSON output and the wire are unchanged.

  • User docs: docs/user/cli/overview.md.
  • Design bets

  • Stable promise: the piped contract, JSON and wire are unchanged. The output changes above are limited to a person at a terminal.

  • No other bet is touched. This is a CLI input path only, with no Machine, store or Cloud behaviour, so there was no Boat swarm (per docs/agents/landing.md).
  • Proof

    Manifest checkout sha = PR head a21bfee1002b3b7f1bcfa4657ee4b9edaf92f150. core/target/debug/ployz was built from that tree. Each run used a fresh PLOYZ_CONFIG lab dir and dummy values, driven on a real pty with python pty.fork.

    | Case | Screen | Exit | Typed value on screen | Echo restored |
    | --- | --- | --- | --- | --- |
    | typed, with a backspace | Value for web.env.M4:, then on to staging (no Cloud in the lab) | 1 (no Cloud) | no | yes |
    | Ctrl-C | Cancelled. Nothing was staged. | 130 | no | yes |
    | Ctrl-D on an empty line | Cancelled. Nothing was staged. | 130 | no | yes |
    | Ctrl-D after text | line taken, on to staging | 1 (no Cloud) | no | yes |
    | empty line, then Ctrl-C | prompt asked again, then cancelled | 130 | no | yes |
    | two-line paste, one write | refused: "That paste held more than one line…" | 2 | no | yes |
    | paste split by 30 ms | refused; the parent shell then read 0 bytes of the tail | 2 | no | yes |
    | paste split by 150 ms | refused; parent read 0 tail bytes | 2 | no | yes |
    | 4 KB line, then a second line | refused; parent read 0 tail bytes | 2 | no | yes |
    | bracketed paste split by 350 ms | refused; parent read 0 tail bytes; paste mode turned on and back off | 2 | no | yes |
    | Ctrl-C 350 ms into an unfinished bracketed paste | Cancelled. Nothing was staged. | 130 | no | yes |
    | bracketed single line, Enter 350 ms later | line taken, on to staging | 1 (no Cloud) | no | yes |
    | piped printf %s <dummy> \| ployz set … | read as before, on to staging | 1 (no Cloud) | no | n/a |

    Secret hygiene (coordinator rule for secret-hygiene lanes): every proof uses dummy values only, and no secret value appears in any output.

  • All pty and piped output was captured raw to mode-600 files on the proof machine.

  • The raw capture was counted for the dummy marker before any filtering. The result is 0 hits, outside the harness's own boolean check lines.

  • The capture was then shown only through a redact filter: sed -E 's/dummy-3414[^[:space:]]*/[REDACTED]/g'.

  • The tables above come from that filtered view.

  • No value, real or dummy, is printed in this PR or in the lane transcript's results.
  • Tests (rung 1, crate unit):

  • ui::prompt::tests::a_hidden_line_ends_at_enter_and_never_keeps_part_of_a_paste covers line endings, backspace over UTF-8, Ctrl-U, Ctrl-W, Ctrl-C, Ctrl-D, and a paste in one read.

  • handlers::config::tests::a_secret_is_never_read_from_a_terminal_that_cant_hide_it_nor_named_in_an_error covers the refusal, a terminal that is never read, the piped trim, and the error codes. The error text leaves out the sentinel.

  • cargo clippy -p ployz --all-targets is clean.
  • Review

    Round 1 was Codex and Opus on the full diff. Both found the swallowed Ctrl-C. Opus also found that a multi-line paste was truncated, and on the second pass that a paste split across reads was truncated and its tail reached the shell. Codex's second pass found the split-paste case too, and that Ctrl-D after text was ignored. All of these are fixed above, with pty proof.

    Round 2 was Codex on the full diff at 96e5a94: no BUG-class findings. The Codex GitHub review then found that a multi-line paste pausing for more than 200 ms was still cut short. This is fixed with bracketed paste in ac319b2, Round 3 (Codex, diff of that fix) found that Ctrl-C inside an unfinished paste was swallowed; fixed in a21bfee. Round 4 (Codex, diff of that fix): no BUG-class findings, so review stops here.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: nick-potts Review duration: 69m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.75) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #3569"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.5% · Safe to merge
    32.5%
    Repository