diff --git a/bin/strongbox.ps1 b/bin/strongbox.ps1 index 6579282..13f794f 100644 --- a/bin/strongbox.ps1 +++ b/bin/strongbox.ps1 @@ -11,14 +11,20 @@ param( [Parameter(Position = 1, ValueFromRemainingArguments)] [string[]] $Rest = @() ) $ErrorActionPreference = 'Stop' + +function Test-InteractiveTerminal { + -not ([Console]::IsInputRedirected -or [Console]::IsOutputRedirected) +} + # get/reveal --stdout are documented as piping-safe ("Print a secret's value to stdout, for -# scripting/piping"). PowerShell's warning stream writes ANSI-colored text directly onto stdout -# in a non-interactive session (no real console attached, e.g. invoked over SSH or from a shell -# script) rather than staying separate from it - the module's own unapproved-verb warning on -# import was landing ahead of the actual secret value in every `strongbox get` capture. Suppress -# warnings for the whole CLI, not just at import, since any future warning anywhere in this -# script's execution would hit the same contamination. -$WarningPreference = 'SilentlyContinue' +# scripting/piping"), which only holds if stdout carries nothing but the secret. In a +# non-interactive session (no real console - SSH, a shell script), PowerShell's warning stream +# writes ANSI-colored text directly onto stdout instead of staying separate from it, so any +# warning anywhere in this script's execution would corrupt a piped capture. A human at a real +# interactive prompt still sees warnings normally. +if (-not (Test-InteractiveTerminal)) { + $WarningPreference = 'SilentlyContinue' +} try { Import-Module Strongbox -ErrorAction Stop @@ -78,10 +84,6 @@ strongbox [args] $script:SandboxSecretName = 'tools.StrongboxSelfTest' -function Test-InteractiveTerminal { - -not ([Console]::IsInputRedirected -or [Console]::IsOutputRedirected) -} - function Assert-RevealAllowed { <# Prevents a script or automated agent from grabbing a real secret when it's only trying to