Skip to content

Commit f02e692

Browse files
authored
Fix credential scan issues (PowerShell#4927)
* Add file secret suppression * Add line secret suppression * This will be consumed in the VSTS daily build. * Renamed tests with ConvertTo-SecureString to avoid false positives
1 parent a8e8b1f commit f02e692

File tree

9 files changed

+30
-3
lines changed

9 files changed

+30
-3
lines changed

demos/Azure/Azure-Demo.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ New-AzureRmResourceGroup -Name $resourceGroupName -Location "West US"
2828
### http://armviz.io/#/?load=https:%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-vm-simple-linux%2Fazuredeploy.json
2929
$dnsLabelPrefix = $resourceGroupName | ForEach-Object tolower
3030
$dnsLabelPrefix
31+
32+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc secret.")]
3133
$password = ConvertTo-SecureString -String "PowerShellRocks!" -AsPlainText -Force
3234
New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile ./Compute-Linux.json -adminUserName psuser -adminPassword $password -dnsLabelPrefix $dnsLabelPrefix
3335

test/powershell/Modules/Microsoft.PowerShell.LocalAccounts/Pester.Command.Cmdlets.LocalAccounts.LocalUser.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ try {
376376
}
377377

378378
It "Can set PasswordNeverExpires to create a user with null for PasswordExpires date" {
379+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
379380
$result = New-LocalUser TestUserNew1 -Password (ConvertTo-SecureString "p@ssw0rd" -Asplaintext -Force) -PasswordNeverExpires
380381

381382
$result.Name | Should BeExactly TestUserNew1
@@ -781,6 +782,7 @@ try {
781782
}
782783

783784
It 'Can use PasswordNeverExpires:$true to null a PasswordExpires date' {
785+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
784786
$user = New-LocalUser TestUserSet2 -Password (ConvertTo-SecureString "p@ssw0rd" -Asplaintext -Force)
785787
$user | Set-LocalUser -PasswordNeverExpires:$true
786788
$result = Get-LocalUser TestUserSet2
@@ -790,6 +792,7 @@ try {
790792
}
791793

792794
It 'Can use PasswordNeverExpires:$false to activate a PasswordExpires date' {
795+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
793796
$user = New-LocalUser TestUserSet2 -Password (ConvertTo-SecureString "p@ssw0rd" -Asplaintext -Force) -PasswordNeverExpires
794797
$user | Set-LocalUser -PasswordNeverExpires:$false
795798
$result = Get-LocalUser TestUserSet2

test/powershell/Modules/Microsoft.PowerShell.Management/Set-Service.Tests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnW
103103
@{parameter = "StartupType" ; value = "System"},
104104
@{parameter = "Credential" ; value = (
105105
[System.Management.Automation.PSCredential]::new("username",
106+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
106107
(ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force)))
107108
}
108109
@{parameter = "DependsOn" ; value = "foo", "bar"}
@@ -257,6 +258,7 @@ Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnW
257258
It "Using bad parameters will fail for '<name>' where '<parameter>' = '<value>'" -TestCases @(
258259
@{cmdlet="New-Service"; name = 'credtest' ; parameter = "Credential" ; value = (
259260
[System.Management.Automation.PSCredential]::new("username",
261+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
260262
(ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force)));
261263
errorid = "CouldNotNewService,Microsoft.PowerShell.Commands.NewServiceCommand"},
262264
@{cmdlet="New-Service"; name = 'badstarttype'; parameter = "StartupType"; value = "System";

test/powershell/Modules/Microsoft.PowerShell.Security/GetCredential.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Describe "Get-Credential Test" -tag "CI" {
9090
$th.ui.Streams.Prompt[-1] | Should Match "Credential:[^:]+:[^:]+"
9191
}
9292
it "Get-Credential `$credential" {
93+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
9394
$password = ConvertTo-SecureString -String "CredTest" -AsPlainText -Force
9495
$credential = [pscredential]::new("John", $password)
9596

test/powershell/Modules/Microsoft.PowerShell.Security/TestData/CatalogTestData/CatalogTestFile2.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<MachineInventory aliasing="True">
22
<Machine machineRole="Server">
33
<Accounts>
4-
<LocalAdmin user="root" password="Bull_dog1" />
4+
<!--[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")] -->
5+
<LocalAdmin user="root" password="PowerShellRocks!" />
56
</Accounts>
67
<BMCMachine>No</BMCMachine>
78
<BranchName>Linux</BranchName>

test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-SecureString.Tests.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
Describe "ConvertTo-SecureString" -Tags "CI" {
1+
Describe "ConvertTo--SecureString" -Tags "CI" {
22

3-
Context "Checking return types of ConvertTo-SecureString" {
3+
Context "Checking return types of ConvertTo--SecureString" {
44

55
It "Should return System.Security.SecureString after converting plaintext variable"{
6+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
67
$PesterTestConvert = (ConvertTo-SecureString "plaintextpester" -AsPlainText -force)
78
$PesterTestConvert | Should BeOfType securestring
89

test/powershell/Modules/Microsoft.WSMan.Management/ConfigProvider.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
158158
}
159159

160160
It "Set-Item on plugin RunAsUser should fail for invalid creds" {
161+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
161162
$password = ConvertTo-SecureString "My voice is my passport, verify me" -AsPlainText -Force
162163
$creds = [pscredential]::new((Get-Random),$password)
163164
$exception = { Set-Item $testPluginPath\RunAsUser $creds } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.SetItemCommand"
@@ -176,13 +177,15 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
176177
}
177178

178179
It "Set-Item on plugin RunAsUser should fail for invalid password" {
180+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
179181
$password = ConvertTo-SecureString "My voice is my passport, verify me" -AsPlainText -Force
180182
$creds = [pscredential]::new($testUser,$password)
181183
$exception = { Set-Item $testPluginPath\RunAsUser $creds } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.SetItemCommand"
182184
$exception.Exception.Message | Should Match ".*$badCredentialError.*"
183185
}
184186

185187
It "Set-Item on password without user on plugin should fail for <password>" -TestCases @(
188+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
186189
@{password=(ConvertTo-SecureString "My voice is my passport, verify me" -AsPlainText -Force)},
187190
@{password="hello"}
188191
) {

test/powershell/engine/Api/Serialization.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Describe "Serialization Tests" -tags "CI" {
8383
}
8484

8585
It 'Test SecureString serialize and deserialize work as expected.' {
86+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
8687
$inputObject = Convertto-Securestring -String "PowerShellRocks!" -AsPlainText -Force
8788
SerializeAndDeserialize($inputObject).Length | Should be $inputObject.Length
8889

tools/credScan/suppress.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"tool": "Credential Scanner",
3+
"suppressions": [
4+
{
5+
"file": "\\test\\tools\\Modules\\WebListener\\ClientCert.pfx",
6+
"_justification": "Test certificate with private key"
7+
},
8+
{
9+
"file": "\\test\\tools\\Modules\\WebListener\\ServerCert.pfx",
10+
"_justification": "Test certificate with private key"
11+
}
12+
]
13+
}

0 commit comments

Comments
 (0)