Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions bin/strongbox.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,10 +84,6 @@ strongbox <command> [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
Expand Down
Loading