[Secrets] CLI set/rotate take the secret value on the command line (history, process list, config parse leak) #35

Closed
opened 2026-11-09 14:39:20 -05:00 by dohertj2 · 1 comment
Owner

From the scadaproj#15 shared-library review (code-reviews/Secrets/findings.md, Secrets-017), verified at 91fb2b4. Update the finding's Resolution row when fixed.

Severity Medium
Priority P2
Category Security & secret handling
Status Open
Location ZB.MOM.WW.Secrets/src/ZB.MOM.WW.Secrets.Cli/Program.cs:21 (values consumed at :57, :65)

Description

The headless verbs take the secret value as a positional argument: set <name> <value> and rotate <name> <value> (lines 57 and 65). There is no stdin or masked-prompt alternative.

The rewrap-all path deliberately refuses literal key material, "which would be echoed/logged" (lines 91–92). Secret values get no such protection: they land in shell history and are visible in the process list (ps, or Windows process command lines in EDR telemetry) to any local user for the duration of the run.

Host.CreateApplicationBuilder(args) (line 21) also feeds the same argv into the command-line configuration provider:

  • A value containing = becomes a configuration key/value pair.
  • A value starting with - and containing = throws an unhandled FormatException. That happens before the verb's catch is set up, and the exception message contains the whole argument.

Failure scenario

secret set db/pw "-p=Hunter2Secret", run from a throwaway probe (not committed), prints:

Unhandled exception. System.FormatException: The short switch '-p=Hunter2Secret' is not defined in the switch mappings.
   at Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.Load()

The secret goes to stderr, which CI logs, deploy-script transcripts and the WinRM output capture all retain. The CLI exits with an unhandled crash rather than its usage code.

Even without the crash, every secret set leaves the plaintext in ~/.zsh_history, PSReadLine history, or the equivalent.

Recommendation

  • Accept the value from stdin (- or --value-stdin) or a masked prompt when stdin is a TTY, and document that as the preferred form.
  • Build the host with Host.CreateApplicationBuilder(new HostApplicationBuilderSettings { Args = [] }), or strip the verb arguments, so argv is never parsed as configuration.
  • Wrap the host build so a configuration exception never echoes argv.

Resolution

Unresolved.

From the scadaproj#15 shared-library review (`code-reviews/Secrets/findings.md`, **Secrets-017**), verified at 91fb2b4. Update the finding's Resolution row when fixed. | | | |--|--| | Severity | Medium | | Priority | P2 | | Category | Security & secret handling | | Status | Open | | Location | `ZB.MOM.WW.Secrets/src/ZB.MOM.WW.Secrets.Cli/Program.cs:21` (values consumed at `:57`, `:65`) | **Description** The headless verbs take the secret value as a positional argument: `set <name> <value>` and `rotate <name> <value>` (lines 57 and 65). There is no stdin or masked-prompt alternative. The `rewrap-all` path deliberately refuses literal key material, "which would be echoed/logged" (lines 91–92). Secret values get no such protection: they land in shell history and are visible in the process list (`ps`, or Windows process command lines in EDR telemetry) to any local user for the duration of the run. `Host.CreateApplicationBuilder(args)` (line 21) also feeds the same argv into the command-line configuration provider: - A value containing `=` becomes a configuration key/value pair. - A value starting with `-` and containing `=` throws an unhandled `FormatException`. That happens before the verb's `catch` is set up, and the exception message contains the whole argument. **Failure scenario** `secret set db/pw "-p=Hunter2Secret"`, run from a throwaway probe (not committed), prints: ```text Unhandled exception. System.FormatException: The short switch '-p=Hunter2Secret' is not defined in the switch mappings. at Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.Load() ``` The secret goes to stderr, which CI logs, deploy-script transcripts and the WinRM output capture all retain. The CLI exits with an unhandled crash rather than its usage code. Even without the crash, every `secret set` leaves the plaintext in `~/.zsh_history`, PSReadLine history, or the equivalent. **Recommendation** - Accept the value from stdin (`-` or `--value-stdin`) or a masked prompt when stdin is a TTY, and document that as the preferred form. - Build the host with `Host.CreateApplicationBuilder(new HostApplicationBuilderSettings { Args = [] })`, or strip the verb arguments, so argv is never parsed as configuration. - Wrap the host build so a configuration exception never echoes argv. **Resolution** _Unresolved._
dohertj2 added the type:review-findingpriority:p2 labels 2026-11-09 14:39:20 -05:00
Author
Owner

Fixed on main 0b610b4 (Secrets-017 → Resolved): set/rotate <name> read the value from piped stdin, -/--value-stdin, or a masked prompt entered twice; the positional value still works with a warning. The CLI no longer feeds command-line args into configuration (old code printed the secret inside a FormatException for -p=…). CLI behaviour changes: no config overrides from the command line (use env vars); startup failure prints secret: startup failed: <message> and exits 1; an unexpected argument is reported by position, not echoed. Evidence: Secrets solution (5 test projects) all pass — Core 246 (1 DPAPI skip), SqlServer 60 (16 live-SQL skips), Akka 44, Grpc 196, Ui 20; each regression test fails with its fix removed. Ships in Secrets 0.6.6 (unpublished).

Fixed on main 0b610b4 (Secrets-017 → Resolved): `set`/`rotate <name>` read the value from piped stdin, `-`/`--value-stdin`, or a masked prompt entered twice; the positional value still works with a warning. The CLI no longer feeds command-line args into configuration (old code printed the secret inside a FormatException for `-p=…`). **CLI behaviour changes:** no config overrides from the command line (use env vars); startup failure prints `secret: startup failed: <message>` and exits 1; an unexpected argument is reported by position, not echoed. Evidence: Secrets solution (5 test projects) all pass — Core 246 (1 DPAPI skip), SqlServer 60 (16 live-SQL skips), Akka 44, Grpc 196, Ui 20; each regression test fails with its fix removed. Ships in Secrets **0.6.6 (unpublished)**.
Sign in to join this conversation.