Azure / Azure/azure-powershell

[TimeSeriesInsights] Please use PtrToStringBSTR instead of PtrToStringAuto for secure string decrytion

Open
#12,957 0 comments 0 reactions 0 assignees View on GitHub
feature-request TimeseriesInsights
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.