Azure / Azure/azure-powershell
[TimeSeriesInsights] Please use PtrToStringBSTR instead of PtrToStringAuto for secure string decrytion
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
## Description
The issue happens in PowerShell 7.* in Linux/MacOS. The root cause is there is breaking change for the API PtrToStringAuto.
To workaround the issue, please follow the sample below to decrpyt secure string.
`$psTxt = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['Password']`
Source code of Unprotect-SecureSting.ps1
```
#This script converts securestring to plaintext
param(
[Parameter(Mandatory, ValueFromPipeline)]
[System.Security.SecureString]
${SecureString}
)
$ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)
try {
$plaintext = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)
} finally {
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ssPtr)
}
return $plaintext
```
https://github.com/Azure/azure-powershell/pull/12842/files
Contributor guide
Assessment
This issue has not been assessed yet.