嚴重性層級:錯誤
說明
此規則偵測該參數的ConvertTo-SecureString使用AsPlainText,該指令繞過加密,將記憶體中的敏感資訊暴露為明文,違背了 SecureString 的初衷。
相反地,透過加密通道取得安全憑證,或使用安全輸入方式 Read-Host -AsSecureString ,確保敏感資料在整個生命週期中保持加密。
建議
如果你需要在沒有使用者介入的情況下以程式方式取得密碼,可以考慮使用 PowerShell 資源庫 的 SecretStore 模組,該模組提供加密的憑證儲存與檢索功能。
範例
不合規
$UserInput = Read-Host 'Please enter your secure code'
$EncryptedInput = ConvertTo-SecureString -String $UserInput -AsPlainText -Force
Compliant
$SecureUserInput = Read-Host 'Please enter your secure code' -AsSecureString