Skip to content

no-plain-text-secure-string

PowerShellsuspiciousno fixdefault: errorpowershell/psscriptanalyzer

Reports a call of ConvertTo-SecureString with -AsPlainText.

It turns a clear-text string into a SecureString, and the clear text is in the script, the history and the logs already. The protection is only in name.

To fix, read the secret as a SecureString (Read-Host -AsSecureString, a vault or Get-Credential).

Reported
...
Get-Help Write-Host
...
ConvertTo-SecureString $p -AsPlainText -Force
ConvertTo-SecureString $p
ConvertTo-SecureString `
$p -AsPlainText
...
Get-CimInstance Win32_Process
ConvertTo-SecureString -AsPlainText "x" -Force
...
function Get-It {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
...
powershell:
lint:
rules:
no-plain-text-secure-string: error # off, warn, error (default)

Enabled by the presets: powershell/psscriptanalyzer.

Suppress one line with sudsy-disable-next-line no-plain-text-secure-string in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
psscriptanalyzer PSAvoidUsingConvertToSecureStringWithPlainText full