Skip to content

Accept a pasted connection JSON at the env set prompt - #2299

Merged
schnie merged 2 commits into
v2from
fix-env-value-paste
Oct 12, 2026
Merged

schnie merged 2 commits into
v2from
fix-env-value-paste

Conversation

@schnie

@schnie schnie commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Pasting a connection into the astro local env connection set prompt failed two ways, both reproduced under a pty:

  • Multi-line JSON was cut at the first newline, so the value was a lone { (and the rest of the paste ran as shell commands).
  • Single-line JSON over 1024 bytes (a GCP keyfile, say) hung: term.ReadPassword reads in the terminal's line mode, and macOS caps a line there at 1024 bytes, dropping the rest, Enter included.

input.HiddenValue reads in raw mode instead, which has no line limit, and turns on bracketed paste so a paste can be told from typing: newlines inside a paste are part of the value, a typed Enter ends it, and a paste ending in a newline ends it. A terminal without bracketed paste falls back to the old behaviour (a newline ends the value).

Also:

  • input.Password uses it too, so the cloud astro env prompt and APC auth get the same fix.
  • Ctrl-C exits 130 (cliout.ExitCode maps input.ErrInterrupted).
  • Line editing: backspace, Ctrl-U, Ctrl-D; CSI/SS3 escape sequences dropped; a bare Esc drops only itself.
  • One-byte reads, so nothing past the value is taken off the terminal.
  • SIGTERM/SIGHUP restore the terminal before exiting.

Checked: unit tests over the byte stream; a pty run of astro local env connection set with a typed value, a 1570-byte line, a bracketed pretty-printed paste (with and without a trailing newline), an unbracketed multi-line paste, a typed {p@ss, and Ctrl-C (exit 130); GOOS=windows build/vet/golangci-lint; make deadcode.

The value prompt read with term.ReadPassword, which uses the terminal's
line mode. Pretty-printed JSON ended at its first newline and arrived as
a lone "{", and macOS caps a line in that mode at 1024 bytes and drops
the rest, Enter included, so a pasted service-account key left the
prompt hanging.

input.HiddenValue reads in raw mode instead. Enter ends the value except
inside a JSON object or array that is still open, so a multi-line paste
ends where the JSON does, and Ctrl-D ends it anywhere.

Co-Authored-By: Claude <noreply@anthropic.com>
@schnie
schnie requested a review from a team as a code owner October 12, 2026 00:04
@coveralls-official

coveralls-official Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 38187551759

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.03%) to 57.706%

Details

  • Coverage increased (+0.03%) from the base build.
  • Patch coverage: 41 uncovered changes across 3 files (104 of 145 lines covered, 71.72%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
pkg/input/hidden.go 138 101 73.19%
cmd/local/env.go 3 0 0.0%
pkg/input/input.go 3 2 66.67%
Total (4 files) 145 104 71.72%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 69596
Covered Lines: 40161
Line Coverage: 57.71%
Coverage Strength: 232.99 hits per line

💛 - Coveralls

Review follow-ups for the hidden value prompt:

- The open-JSON rule swallowed Enter for any value starting with an
  unclosed { or [, a password included, and did nothing for a non-JSON
  multi-line paste such as a PEM key, whose later lines ran as shell
  commands. The prompt now turns on bracketed paste: newlines inside a
  paste are part of the value, a typed Enter ends it, and a paste ending
  in a newline ends it as pasting a line always has.
- Ctrl-C exited 1. cliout.ExitCode now maps input.ErrInterrupted to 130.
- input.Password, behind the cloud env prompt and APC auth, still used
  term.ReadPassword and had the same paste bugs. It uses HiddenValue.
- Reads are one byte at a time, so nothing past the value is taken off
  the terminal and lost.
- ESC O sequences (function keys, application-mode arrows) are skipped,
  and a bare Esc no longer eats the key after it.
- SIGTERM and SIGHUP put the terminal back before exiting, so a killed
  prompt does not leave the shell without echo.

Co-Authored-By: Claude <noreply@anthropic.com>
@schnie
schnie merged commit 8a6b4ff into v2 Oct 12, 2026
6 checks passed
@schnie
schnie deleted the fix-env-value-paste branch October 12, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant