PowerShell / PowerShell/PSScriptAnalyzer
Rule request: `AvoidSecureStringDisclosure`
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
As for AvoidUsingConvertToSecureStringWithPlainText it should be avoided to retrieve a PlainText password from a SecureString as it might leave memory trials (or even logging trails).
$Password = $SecureString | ConvertFrom-SecureString -AsPlainText
Besides, the action that follows and requires the plaintext password is likely vulnerable from a security aspect.
This will also include the common used statements as:
(see: https://stackoverflow.com/a/28353003/1701026)
$SecurePassword = ConvertTo-SecureString $PlainPassword -AsPlainText -Force
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
$Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR)
and (see: https://stackoverflow.com/a/40166959/1701026):
$Password = (New-Object PSCredential 0, $SecurePassword).GetNetworkCredential().Password
The general approach of dealing with credentials is to avoid them and instead rely on other means to authenticate, such as certificates or Windows authentication.
Proposed technical implementation details (optional)
Create rules to check for the above mentioned unsafe statements.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing PSScriptAnalyzer rule implementations and tests, then compare their handling of ConvertFrom-SecureString, SecureStringToBSTR, and PSCredential.GetNetworkCredential(). The work is done when unsafe SecureString-to-plaintext patterns are reliably reported and corresponding analyzer tests cover the examples in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- security, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100