Skip to content

Commit 6465ecd

Browse files
committed
PS: Add GUIDs as a simple sanitizer, and accept test changes.
1 parent 6da1c01 commit 6465ecd

3 files changed

Lines changed: 3 additions & 19 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/SqlInjection.expected

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,12 @@ edges
1919
| test.ps1:78:49:78:58 | userinput | test.ps1:78:13:78:59 | SELECT * FROM Customers WHERE id = $userinput | provenance | Config |
2020
| test.ps1:78:49:78:58 | userinput | test.ps1:111:51:111:60 | userinput | provenance | |
2121
| test.ps1:111:51:111:60 | userinput | test.ps1:128:28:128:37 | userinput | provenance | |
22-
| test.ps1:111:51:111:60 | userinput | test.ps1:150:10:150:19 | userinput | provenance | |
2322
| test.ps1:121:9:121:56 | unvalidated | test.ps1:125:130:125:141 | unvalidated | provenance | |
2423
| test.ps1:125:128:125:142 | $(...) | test.ps1:125:92:125:143 | SELECT * FROM Customers where id = $($unvalidated) | provenance | |
2524
| test.ps1:125:128:125:142 | $(...) | test.ps1:125:92:125:143 | SELECT * FROM Customers where id = $($unvalidated) | provenance | Config |
2625
| test.ps1:125:130:125:141 | unvalidated | test.ps1:125:128:125:142 | $(...) | provenance | |
2726
| test.ps1:125:130:125:141 | unvalidated | test.ps1:125:128:125:142 | $(...) | provenance | Config |
2827
| test.ps1:128:28:128:37 | userinput | test.ps1:121:9:121:56 | unvalidated | provenance | |
29-
| test.ps1:144:11:144:50 | r | test.ps1:146:55:146:56 | r | provenance | |
30-
| test.ps1:146:5:146:10 | query | test.ps1:147:72:147:77 | query | provenance | |
31-
| test.ps1:146:5:146:10 | query | test.ps1:147:72:147:77 | query | provenance | |
32-
| test.ps1:146:14:146:58 | SELECT * FROM MyTable WHERE MyColumn = '$r' | test.ps1:146:5:146:10 | query | provenance | |
33-
| test.ps1:146:14:146:58 | SELECT * FROM MyTable WHERE MyColumn = '$r' | test.ps1:146:5:146:10 | query | provenance | |
34-
| test.ps1:146:55:146:56 | r | test.ps1:146:14:146:58 | SELECT * FROM MyTable WHERE MyColumn = '$r' | provenance | Config |
35-
| test.ps1:150:10:150:19 | userinput | test.ps1:144:11:144:50 | r | provenance | |
3628
nodes
3729
| test.ps1:1:1:1:10 | userinput | semmle.label | userinput |
3830
| test.ps1:1:14:1:45 | Call to read-host | semmle.label | Call to read-host |
@@ -60,13 +52,6 @@ nodes
6052
| test.ps1:125:128:125:142 | $(...) | semmle.label | $(...) |
6153
| test.ps1:125:130:125:141 | unvalidated | semmle.label | unvalidated |
6254
| test.ps1:128:28:128:37 | userinput | semmle.label | userinput |
63-
| test.ps1:144:11:144:50 | r | semmle.label | r |
64-
| test.ps1:146:5:146:10 | query | semmle.label | query |
65-
| test.ps1:146:5:146:10 | query | semmle.label | query |
66-
| test.ps1:146:14:146:58 | SELECT * FROM MyTable WHERE MyColumn = '$r' | semmle.label | SELECT * FROM MyTable WHERE MyColumn = '$r' |
67-
| test.ps1:146:55:146:56 | r | semmle.label | r |
68-
| test.ps1:147:72:147:77 | query | semmle.label | query |
69-
| test.ps1:150:10:150:19 | userinput | semmle.label | userinput |
7055
subpaths
7156
#select
7257
| test.ps1:5:72:5:77 | query | test.ps1:1:14:1:45 | Call to read-host | test.ps1:5:72:5:77 | query | This SQL query depends on a $@. | test.ps1:1:14:1:45 | Call to read-host | read from stdin |
@@ -75,4 +60,3 @@ subpaths
7560
| test.ps1:28:24:28:76 | SELECT * FROM MyTable WHERE MyColumn = '$userinput' | test.ps1:1:14:1:45 | Call to read-host | test.ps1:28:24:28:76 | SELECT * FROM MyTable WHERE MyColumn = '$userinput' | This SQL query depends on a $@. | test.ps1:1:14:1:45 | Call to read-host | read from stdin |
7661
| test.ps1:81:15:81:25 | QueryConn2 | test.ps1:1:14:1:45 | Call to read-host | test.ps1:81:15:81:25 | QueryConn2 | This SQL query depends on a $@. | test.ps1:1:14:1:45 | Call to read-host | read from stdin |
7762
| test.ps1:125:92:125:143 | SELECT * FROM Customers where id = $($unvalidated) | test.ps1:1:14:1:45 | Call to read-host | test.ps1:125:92:125:143 | SELECT * FROM Customers where id = $($unvalidated) | This SQL query depends on a $@. | test.ps1:1:14:1:45 | Call to read-host | read from stdin |
78-
| test.ps1:147:72:147:77 | query | test.ps1:1:14:1:45 | Call to read-host | test.ps1:147:72:147:77 | query | This SQL query depends on a $@. | test.ps1:1:14:1:45 | Call to read-host | read from stdin |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function WithGuid {
144144
PARAM([Parameter(Mandatory = $true)] [guid] $r)
145145

146146
$query = "SELECT * FROM MyTable WHERE MyColumn = '$r'"
147-
Invoke-Sqlcmd -ServerInstance "MyServer" -Database "MyDatabase" -q $query # GOOD [FALSE POSITIVE]
147+
Invoke-Sqlcmd -ServerInstance "MyServer" -Database "MyDatabase" -q $query # GOOD
148148
}
149149

150150
WithGuid $userinput

0 commit comments

Comments
 (0)