Skip to content

Add new AvoidSecretDisclosure rule#2183

Open
iRon7 wants to merge 3 commits intoPowerShell:mainfrom
iRon7:AvoidSecureStringDisclosure
Open

Add new AvoidSecretDisclosure rule#2183
iRon7 wants to merge 3 commits intoPowerShell:mainfrom
iRon7:AvoidSecureStringDisclosure

Conversation

@iRon7
Copy link
Copy Markdown

@iRon7 iRon7 commented May 6, 2026

PR Summary

Rule request: #1997

Description

Disclosing a secret might result in security vulnerabilities such as memory trails or logging trails that could
be exploited by attackers. This rule identifies instances where a secret is being converted to plain text,
which can lead to unintended exposure of sensitive information.

Important

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.

How to Fix

In general, avoid any code pattern that involves converting secrets to plaintext or accessing plaintext secrets.

  • For ConvertFrom-SecureString -AsPlainText: Use -Credential parameter instead
  • For SecureStringTo* methods: Avoid converting to plaintext
  • For Password properties: Use secure credential objects directly or the SecureString equivalent
    SecurePassword instead of accessing plaintext passwords.

Note

For custom properties named "Password", it is recommended to rename them to something that does not imply they
contain secrets, or to ensure that they do not actually contain secrets. If renaming is not possible, consider
suppressing the warning for those specific cases.

PR Checklist

Copilot AI review requested due to automatic review settings May 6, 2026 09:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new built-in PSScriptAnalyzer rule (PSAvoidSecretDisclosure) to flag common patterns that convert secrets (e.g., SecureString) into plaintext, with accompanying tests, localized strings, and documentation.

Changes:

  • Introduces AvoidSecretDisclosure rule implementation to detect ConvertFrom-SecureString -AsPlainText, SecureStringTo* calls, and .Password member access.
  • Adds Pester tests covering violations, compliant examples, and suppression scenarios.
  • Updates rule documentation and the rules index, and adds localized strings for name/common name/description/error.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
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.

Comment thread Rules/AvoidSecretDisclosure.cs
Comment thread Rules/AvoidSecretDisclosure.cs Outdated
Comment thread docs/Rules/AvoidSecretDisclosure.md
Comment thread Tests/Rules/AvoidSecretDisclosure.tests.ps1
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants