-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update powershell sanitizer regex (#1199)
* Updated regex to allow more characters Copy of microsoft/azure-pipelines-tasks#19028 * Bump extension and tasks versions
- Loading branch information
1 parent
70c2754
commit 6a88be6
Showing
28 changed files
with
114 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 5, | ||
"Patch": 5 | ||
"Patch": 6 | ||
}, | ||
"demands": [ | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 1, | ||
"Patch": 5 | ||
"Patch": 6 | ||
}, | ||
"demands": [ | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 4, | ||
"Patch": 5 | ||
"Patch": 6 | ||
}, | ||
"demands": [ | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 2, | ||
"Patch": 5 | ||
"Patch": 6 | ||
}, | ||
"demands": [ | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
"version": { | ||
"Major": 3, | ||
"Minor": 1, | ||
"Patch": 5 | ||
"Patch": 6 | ||
}, | ||
"demands": [ | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 4, | ||
"Patch": 6 | ||
"Patch": 7 | ||
}, | ||
"demands": [ | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 1, | ||
"Patch": 6 | ||
"Patch": 7 | ||
}, | ||
"demands": [ | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
TaskModules/powershell/Sanitizer/Strings/resources.resjson/de-DE/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
2 changes: 1 addition & 1 deletion
2
TaskModules/powershell/Sanitizer/Strings/resources.resjson/en-US/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"loc.messages.PS_ScriptArgsSanitized": "Detected characters in arguments that may not be executed correctly by the shell. Please escape special characters using backtick (`). More information is available here: <https://aka.ms/ado/75787>", | ||
"loc.messages.PS_ScriptArgsSanitized": "Detected characters in arguments that may not be executed correctly by the shell. Please escape special characters using backtick (`). More information is available here: https://aka.ms/ado/75787", | ||
"loc.messages.PS_ScriptArgsNotSanitized": "Arguments passed sanitization without change." | ||
} |
2 changes: 2 additions & 0 deletions
2
TaskModules/powershell/Sanitizer/Strings/resources.resjson/es-ES/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
2 changes: 2 additions & 0 deletions
2
TaskModules/powershell/Sanitizer/Strings/resources.resjson/fr-FR/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
2 changes: 2 additions & 0 deletions
2
TaskModules/powershell/Sanitizer/Strings/resources.resjson/it-IT/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
2 changes: 2 additions & 0 deletions
2
TaskModules/powershell/Sanitizer/Strings/resources.resjson/ja-JP/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
2 changes: 2 additions & 0 deletions
2
TaskModules/powershell/Sanitizer/Strings/resources.resjson/ko-KR/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
2 changes: 2 additions & 0 deletions
2
TaskModules/powershell/Sanitizer/Strings/resources.resjson/ru-RU/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
2 changes: 2 additions & 0 deletions
2
TaskModules/powershell/Sanitizer/Strings/resources.resjson/zh-CN/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
2 changes: 2 additions & 0 deletions
2
TaskModules/powershell/Sanitizer/Strings/resources.resjson/zh-TW/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
TaskModules/powershell/Sanitizer/Tests/L0Protect-ScriptArguments.Passes.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[CmdletBinding()] | ||
param() | ||
|
||
Set-Item -Path env:AZP_75787_ENABLE_NEW_LOGIC -Value 'true' | ||
|
||
. $PSScriptRoot\..\..\..\..\Tests\lib\Initialize-Test.ps1 | ||
. $PSScriptRoot\..\ArgumentsSanitizer.ps1 | ||
|
||
$inputArgsSuites = @( | ||
"/parameter", # Traditional way to pass parameters in CMD | ||
"-parameter", # Modern applications accept parameters with a hyphen | ||
"--parameter", # Many modern applications accept parameters with double hyphen | ||
"parameter=value", # Format for passing values to parameters | ||
"parameter value.txt", # Argument with dot in the middle | ||
"-parameter", # Single hyphen followed by a single letter or digit (POSIX style) | ||
"-parameter value", # When the parameter needs a value | ||
"--parameter", # Double hyphen followed by a word (GNU style) | ||
"--parameter=value", # Value directly attached to the parameter with an equals sign | ||
"parameter=value", # Used to pass environment variables to a command | ||
"parameter value.txt", # Argument with dot in the middle | ||
"-Parameter Value", # Most common form | ||
"-Parameter:Value", # Colon connects the parameter and its value | ||
"/p:Parameter=Value", # Specific syntax for tools like MSBuild or NuGet | ||
"--Parameter Value", # Used by cmdlets or scripts for cross-platform compatibility | ||
"--Parameter=Value", # Used by cross-platform tools | ||
"parameter value.txt" # Argument with dot in the middle | ||
'a A 1 \ ` _ '' " - = / : . * , + ~ ? %', # Just each allowed symbol | ||
'', | ||
'test 1', | ||
'test `; whoami `&`& echo test', | ||
"line 1 `n line 2" | ||
) | ||
|
||
foreach ($inputArgs in $inputArgsSuites) { | ||
try { | ||
Protect-ScriptArguments $inputArgs | ||
} | ||
catch { | ||
throw "Error occured with '$inputArgs' input args: $($_.Exception.Message)" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
TaskModules/powershell/Sanitizer/Tests/L0Protect-ScriptArguments.Throws.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[CmdletBinding()] | ||
param() | ||
|
||
Set-Item -Path env:AZP_75787_ENABLE_NEW_LOGIC -Value 'true' | ||
|
||
. $PSScriptRoot\..\..\..\..\Tests\lib\Initialize-Test.ps1 | ||
. $PSScriptRoot\..\ArgumentsSanitizer.ps1 | ||
|
||
$inputArgsSuites = @( | ||
'test; whoami', | ||
'test && whoami', | ||
'echo "$(rm ./somedir)"', | ||
'test | whoami' | ||
) | ||
|
||
$expectedMsg = Get-VstsLocString -Key 'PS_ScriptArgsSanitized' | ||
|
||
foreach ($inputArgs in $inputArgsSuites) { | ||
Assert-Throws { | ||
Protect-ScriptArguments $inputArgs | ||
} -MessagePattern $expectedMsg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"messages": { | ||
"PS_ScriptArgsSanitized": "Detected characters in arguments that may not be executed correctly by the shell. Please escape special characters using backtick (`). More information is available here: <https://aka.ms/ado/75787>", | ||
"PS_ScriptArgsSanitized": "Detected characters in arguments that may not be executed correctly by the shell. Please escape special characters using backtick (`). More information is available here: https://aka.ms/ado/75787", | ||
"PS_ScriptArgsNotSanitized": "Arguments passed sanitization without change." | ||
} | ||
} |