Skip to content

Commit b85c176

Browse files
committed
PS: Add a FP to the sql-injection query.
1 parent 6df032d commit b85c176

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

powershell/ql/test/query-tests/security/cwe-089/SqlInjection.expected

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ edges
44
| test.ps1:1:1:1:10 | userinput | test.ps1:17:24:17:76 | SELECT * FROM MyTable WHERE MyColumn = '$userinput' | provenance | |
55
| test.ps1:1:1:1:10 | userinput | test.ps1:28:24:28:76 | SELECT * FROM MyTable WHERE MyColumn = '$userinput' | provenance | |
66
| test.ps1:1:1:1:10 | userinput | test.ps1:78:13:78:22 | userinput | provenance | |
7+
| test.ps1:1:1:1:10 | userinput | test.ps1:128:17:128:26 | userinput | provenance | |
8+
| test.ps1:1:1:1:10 | userinput | test.ps1:128:28:128:37 | userinput | provenance | |
79
| test.ps1:1:14:1:45 | Call to read-host | test.ps1:1:1:1:10 | userinput | provenance | Src:MaD:0 |
810
| test.ps1:4:1:4:6 | query | test.ps1:5:72:5:77 | query | provenance | |
911
| test.ps1:8:1:8:6 | query | test.ps1:9:72:9:77 | query | provenance | |
1012
| test.ps1:72:1:72:11 | QueryConn2 [element Query] | test.ps1:81:15:81:25 | QueryConn2 | provenance | |
1113
| test.ps1:72:15:79:1 | ${...} [element Query] | test.ps1:72:1:72:11 | QueryConn2 [element Query] | provenance | |
1214
| test.ps1:78:13:78:22 | userinput | test.ps1:72:15:79:1 | ${...} [element Query] | provenance | |
15+
| test.ps1:118:9:119:54 | validated | test.ps1:124:92:124:101 | validated | provenance | |
16+
| test.ps1:121:9:121:56 | unvalidated | test.ps1:125:92:125:103 | unvalidated | provenance | |
17+
| test.ps1:128:17:128:26 | userinput | test.ps1:118:9:119:54 | validated | provenance | |
18+
| test.ps1:128:28:128:37 | userinput | test.ps1:121:9:121:56 | unvalidated | provenance | |
1319
nodes
1420
| test.ps1:1:1:1:10 | userinput | semmle.label | userinput |
1521
| test.ps1:1:14:1:45 | Call to read-host | semmle.label | Call to read-host |
@@ -23,10 +29,18 @@ nodes
2329
| test.ps1:72:15:79:1 | ${...} [element Query] | semmle.label | ${...} [element Query] |
2430
| test.ps1:78:13:78:22 | userinput | semmle.label | userinput |
2531
| test.ps1:81:15:81:25 | QueryConn2 | semmle.label | QueryConn2 |
32+
| test.ps1:118:9:119:54 | validated | semmle.label | validated |
33+
| test.ps1:121:9:121:56 | unvalidated | semmle.label | unvalidated |
34+
| test.ps1:124:92:124:101 | validated | semmle.label | validated |
35+
| test.ps1:125:92:125:103 | unvalidated | semmle.label | unvalidated |
36+
| test.ps1:128:17:128:26 | userinput | semmle.label | userinput |
37+
| test.ps1:128:28:128:37 | userinput | semmle.label | userinput |
2638
subpaths
2739
#select
2840
| 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 |
2941
| test.ps1:9:72:9:77 | query | test.ps1:1:14:1:45 | Call to read-host | test.ps1:9:72:9:77 | query | This SQL query depends on a $@. | test.ps1:1:14:1:45 | Call to read-host | read from stdin |
3042
| test.ps1:17:24:17:76 | SELECT * FROM MyTable WHERE MyColumn = '$userinput' | test.ps1:1:14:1:45 | Call to read-host | test.ps1:17:24:17: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 |
3143
| 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 |
3244
| 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 |
45+
| test.ps1:124:92:124:101 | validated | test.ps1:1:14:1:45 | Call to read-host | test.ps1:124:92:124:101 | validated | This SQL query depends on a $@. | test.ps1:1:14:1:45 | Call to read-host | read from stdin |
46+
| test.ps1:125:92:125:103 | unvalidated | test.ps1:1:14:1:45 | Call to read-host | test.ps1:125:92:125:103 | unvalidated | 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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,18 @@ TakesTypedParameters $userinput $userinput $userinput $userinput $userinput $use
111111
$query = "SELECT * FROM MyTable WHERE MyColumn = '$userinput'"
112112
Invoke-Sqlcmd -unknown $userinput -ServerInstance "MyServer" -Database "MyDatabase" -q "SELECT * FROM MyTable" # GOOD
113113

114-
Invoke-Sqlcmd -ServerInstance "MyServer" -Database "MyDatabase" -InputFile $userinput # GOOD # this is not really what this query is about.
114+
Invoke-Sqlcmd -ServerInstance "MyServer" -Database "MyDatabase" -InputFile $userinput # GOOD # this is not really what this query is about.
115+
116+
function With-Validation() {
117+
param(
118+
[ValidateSet("FirstName","LastName")]
119+
[parameter(Mandatory=$true)][string]$validated,
120+
121+
[parameter(Mandatory=$true)][string]$unvalidated
122+
)
123+
124+
Invoke-Sqlcmd -unknown $userinput -ServerInstance "MyServer" -Database "MyDatabase" -q $validated # GOOD [FALSE POSITIVE]
125+
Invoke-Sqlcmd -unknown $userinput -ServerInstance "MyServer" -Database "MyDatabase" -q $unvalidated # BAD
126+
}
127+
128+
With-Validation $userinput $userinput

0 commit comments

Comments
 (0)