Skip to content

Commit ac52680

Browse files
authored
Merge pull request #350 from microsoft/guid-sanitizer-ps
PS: Add GUID as simple sanitizers
2 parents 9bafbaf + 6465ecd commit ac52680

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

powershell/ql/lib/semmle/code/powershell/security/Sanitizers.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ private import semmle.code.powershell.dataflow.DataFlow
44
/**
55
* A dataflow node that is guarenteed to have a "simple" type.
66
*
7-
* Simple types include integers, floats, characters, booleans, and `datetime`.
7+
* Simple types include integers, floats, characters, booleans, `datetime`, and `guid`.
88
*/
99
class SimpleTypeSanitizer extends DataFlow::Node {
1010
SimpleTypeSanitizer() {
1111
this.asParameter().getStaticType() =
12-
["int32", "int64", "single", "double", "decimal", "char", "boolean", "datetime"]
12+
["int32", "int64", "single", "double", "decimal", "char", "boolean", "datetime", "guid"]
1313
}
1414
}

powershell/ql/test/query-tests/security/cwe-089/test.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,13 @@ $QueryConn3 = @{
138138

139139
Invoke-Sqlcmd @QueryConn3 # GOOD
140140

141-
&sqlcmd -e -S $userinput -U "Login" -P "MyPassword" -d "MyDBName" -i "input_file.sql" # GOOD
141+
&sqlcmd -e -S $userinput -U "Login" -P "MyPassword" -d "MyDBName" -i "input_file.sql" # GOOD
142+
143+
function WithGuid {
144+
PARAM([Parameter(Mandatory = $true)] [guid] $r)
145+
146+
$query = "SELECT * FROM MyTable WHERE MyColumn = '$r'"
147+
Invoke-Sqlcmd -ServerInstance "MyServer" -Database "MyDatabase" -q $query # GOOD
148+
}
149+
150+
WithGuid $userinput

0 commit comments

Comments
 (0)