GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add new AvoidSecretDisclosure rule by iRon7 · Pull Request #2183 · PowerShell/PSScriptAnalyzer Conversation
|
| File | Description |
|---|---|
| Tests/Rules/AvoidSecretDisclosure.tests.ps1 | Adds Pester coverage for the new rule (violations/compliance/suppression). |
| Rules/Strings.resx | Adds localized strings for the new rule’s name/common name/description/message. |
| Rules/AvoidSecretDisclosure.cs | Implements the new analyzer rule logic and diagnostic creation. |
| docs/Rules/README.md | Registers the rule in the published rules list/table. |
| docs/Rules/AvoidSecretDisclosure.md | Adds the rule’s public documentation page and examples. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added suggestions for style and one question about the parameter.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Sean Wheeler <[email protected]>
Co-authored-by: Sean Wheeler <[email protected]>
Co-authored-by: Sean Wheeler <[email protected]>
Co-authored-by: Sean Wheeler <[email protected]>
Co-authored-by: Sean Wheeler <[email protected]>
…ble in a future release after giving users time to adjust.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
There is already a AvoidUsingConvertToSecureStringWithPlainText therefore if we were ti have a general rule to alert on things like SecureString methods, then the old rule logic should be merged into this one and there should be configuration on what to alert for. For example on Linux, Credential does not apply. And on Linux SecureString is not implemented and since .NET 5, Securestring was marked as obsolete and not recommended any more as it is understood that practically it is and was never more secure in first place.
Since it's an optional rule, we can be opinionated but in practice many warnings will not be fixable and we found that this can be a source of frustration for community.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Christoph Bergmeister (@bergmeister), The difference with the existing
Agree, this rule should be disabled by default for continuous integration usage and enabled manually as it will certainly reveal a lot of security violations in the currently installed bases... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Docs look good.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Since about 3 weeks ago, I have created 6 PR for new rules (the last one was from yesterday: #2186). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The rule currently misses valid disclosure syntax, reports a secure PSCredential.Password access, and provides misleading remediation guidance.
Get a fresh assessment by requesting another Copilot review.
Rules/AvoidSecretDisclosure.cs:76
[Marshal]::'SecureStringToBSTR'(...) invokes the same conversion, but matching the member's source text can retain the quotes and fail this prefix check. Match StringConstantExpressionAst.Value instead and use that normalized value for the suppression ID. testAst is InvokeMemberExpressionAst invokeAst &&
invokeAst.Member != null &&
invokeAst.Member.ToString().StartsWith("SecureStringTo", StringComparison.OrdinalIgnoreCase),
Rules/AvoidSecretDisclosure.cs:94
[PSCredential].Password, whose value is already a SecureString; reading it does not disclose plaintext and is a valid input to APIs that accept SecureString. Exclude properties that can be resolved to SecureString (at least statically typed PSCredential instances), while retaining the heuristic only where the property type is unknown or plaintext. IEnumerable<MemberExpressionAst> passwordAsts = ast.FindAll(testAst =>
testAst is MemberExpressionAst memberAst &&
memberAst.Member != null &&
string.Equals(memberAst.Member.ToString(), "Password", StringComparison.OrdinalIgnoreCase),
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| cmdAst.GetCommandName() != null && | ||
| cmdAst.GetCommandName().Equals("ConvertFrom-SecureString", StringComparison.OrdinalIgnoreCase), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
whilst it would be good to also cater for module qualified, current approach is good enough IMHO
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| In general, avoid any code pattern that involves converting secrets to plaintext or accessing | ||
| plaintext secrets. | ||
|
|
||
| - For `ConvertFrom-SecureString -AsPlainText`: Use `-Credential` parameter instead |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
iRon7 maybe I am reading this with not enough context but what do you mean by -Credential parameter?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
happy with it, first copilot suggestion I see as optional improvement. Just a reply please on last one to clarify what you mean with -Credential param
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Christoph Bergmeister (@bergmeister), Thanks you for your approvals
I agree, this is indeed a big jump into a "solution", what I meant is exactly how copilot expresses it:
(See also the example) Which, I am aware, isn't often available, leaving just the general approach of dealing with credentials (avoid them). Also knowing that this is in most an issue due to the capabilities or configuration of a third party application and not something that can be securely fixed in the concerned PowerShell script. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
At least 1 approving review is required to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Rule request:AvoidSecureStringDisclosure
There was an error while loading. Please reload this page.