Skip to content

Commit 72f8680

Browse files
committed
remove Invoke-WebRequest as source
1 parent e66ae68 commit 72f8680

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,19 @@ module CommandInjection {
3434
class FlowSourceAsSource extends Source {
3535
FlowSourceAsSource() {
3636
this instanceof SourceNode and
37-
not this instanceof EnvironmentVariableSource
37+
not this instanceof EnvironmentVariableSource and
38+
not this instanceof InvokeWebRequest
3839
}
3940

4041
override string getSourceType() { result = "user-provided value" }
4142
}
4243

44+
class InvokeWebRequest extends DataFlow::CallNode {
45+
InvokeWebRequest(){
46+
this.matchesName("Invoke-WebRequest")
47+
}
48+
}
49+
4350
/**
4451
* A command argument to a function that initiates an operating system command.
4552
*/

powershell/ql/test/query-tests/security/cwe-078/CommandInjection/CommandInjection.expected

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ edges
6161
| test.ps1:185:42:185:47 | input | test.ps1:144:11:144:20 | userinput | provenance | |
6262
| test.ps1:186:58:186:63 | input | test.ps1:153:11:153:20 | userinput | provenance | |
6363
| test.ps1:187:41:187:46 | input | test.ps1:159:11:159:20 | userinput | provenance | |
64-
| test.ps1:245:5:245:6 | o | test.ps1:248:7:248:10 | $o | provenance | |
65-
| test.ps1:245:10:245:32 | Call to read-host | test.ps1:245:5:245:6 | o | provenance | Src:MaD:0 |
66-
| test.ps1:256:5:256:10 | input | test.ps1:257:5:257:21 | env:bar | provenance | |
67-
| test.ps1:256:5:256:10 | input | test.ps1:257:5:257:21 | env:bar | provenance | |
68-
| test.ps1:256:14:256:36 | Call to read-host | test.ps1:256:5:256:10 | input | provenance | Src:MaD:0 |
69-
| test.ps1:256:14:256:36 | Call to read-host | test.ps1:256:5:256:10 | input | provenance | Src:MaD:0 |
70-
| test.ps1:257:5:257:21 | env:bar | test.ps1:259:5:259:6 | y | provenance | |
71-
| test.ps1:259:5:259:6 | y | test.ps1:260:7:260:10 | $y | provenance | |
64+
| test.ps1:254:5:254:6 | o | test.ps1:257:7:257:10 | $o | provenance | |
65+
| test.ps1:254:10:254:32 | Call to read-host | test.ps1:254:5:254:6 | o | provenance | Src:MaD:0 |
66+
| test.ps1:265:5:265:10 | input | test.ps1:266:5:266:21 | env:bar | provenance | |
67+
| test.ps1:265:5:265:10 | input | test.ps1:266:5:266:21 | env:bar | provenance | |
68+
| test.ps1:265:14:265:36 | Call to read-host | test.ps1:265:5:265:10 | input | provenance | Src:MaD:0 |
69+
| test.ps1:265:14:265:36 | Call to read-host | test.ps1:265:5:265:10 | input | provenance | Src:MaD:0 |
70+
| test.ps1:266:5:266:21 | env:bar | test.ps1:268:5:268:6 | y | provenance | |
71+
| test.ps1:268:5:268:6 | y | test.ps1:269:7:269:10 | $y | provenance | |
7272
nodes
7373
| test.ps1:3:11:3:20 | userinput | semmle.label | userinput |
7474
| test.ps1:4:23:4:52 | Get-Process -Name $UserInput | semmle.label | Get-Process -Name $UserInput |
@@ -133,15 +133,15 @@ nodes
133133
| test.ps1:185:42:185:47 | input | semmle.label | input |
134134
| test.ps1:186:58:186:63 | input | semmle.label | input |
135135
| test.ps1:187:41:187:46 | input | semmle.label | input |
136-
| test.ps1:245:5:245:6 | o | semmle.label | o |
137-
| test.ps1:245:10:245:32 | Call to read-host | semmle.label | Call to read-host |
138-
| test.ps1:248:7:248:10 | $o | semmle.label | $o |
139-
| test.ps1:256:5:256:10 | input | semmle.label | input |
140-
| test.ps1:256:5:256:10 | input | semmle.label | input |
141-
| test.ps1:256:14:256:36 | Call to read-host | semmle.label | Call to read-host |
142-
| test.ps1:257:5:257:21 | env:bar | semmle.label | env:bar |
143-
| test.ps1:259:5:259:6 | y | semmle.label | y |
144-
| test.ps1:260:7:260:10 | $y | semmle.label | $y |
136+
| test.ps1:254:5:254:6 | o | semmle.label | o |
137+
| test.ps1:254:10:254:32 | Call to read-host | semmle.label | Call to read-host |
138+
| test.ps1:257:7:257:10 | $o | semmle.label | $o |
139+
| test.ps1:265:5:265:10 | input | semmle.label | input |
140+
| test.ps1:265:5:265:10 | input | semmle.label | input |
141+
| test.ps1:265:14:265:36 | Call to read-host | semmle.label | Call to read-host |
142+
| test.ps1:266:5:266:21 | env:bar | semmle.label | env:bar |
143+
| test.ps1:268:5:268:6 | y | semmle.label | y |
144+
| test.ps1:269:7:269:10 | $y | semmle.label | $y |
145145
subpaths
146146
#select
147147
| test.ps1:4:23:4:52 | Get-Process -Name $UserInput | test.ps1:164:10:164:32 | Call to read-host | test.ps1:4:23:4:52 | Get-Process -Name $UserInput | This command depends on a $@. | test.ps1:164:10:164:32 | Call to read-host | user-provided value |
@@ -164,5 +164,5 @@ subpaths
164164
| test.ps1:147:63:147:72 | UserInput | test.ps1:164:10:164:32 | Call to read-host | test.ps1:147:63:147:72 | UserInput | This command depends on a $@. | test.ps1:164:10:164:32 | Call to read-host | user-provided value |
165165
| test.ps1:154:23:154:52 | Get-Process -Name $UserInput | test.ps1:164:10:164:32 | Call to read-host | test.ps1:154:23:154:52 | Get-Process -Name $UserInput | This command depends on a $@. | test.ps1:164:10:164:32 | Call to read-host | user-provided value |
166166
| test.ps1:160:29:160:38 | UserInput | test.ps1:164:10:164:32 | Call to read-host | test.ps1:160:29:160:38 | UserInput | This command depends on a $@. | test.ps1:164:10:164:32 | Call to read-host | user-provided value |
167-
| test.ps1:248:7:248:10 | $o | test.ps1:245:10:245:32 | Call to read-host | test.ps1:248:7:248:10 | $o | This command depends on a $@. | test.ps1:245:10:245:32 | Call to read-host | user-provided value |
168-
| test.ps1:260:7:260:10 | $y | test.ps1:256:14:256:36 | Call to read-host | test.ps1:260:7:260:10 | $y | This command depends on a $@. | test.ps1:256:14:256:36 | Call to read-host | user-provided value |
167+
| test.ps1:257:7:257:10 | $o | test.ps1:254:10:254:32 | Call to read-host | test.ps1:257:7:257:10 | $o | This command depends on a $@. | test.ps1:254:10:254:32 | Call to read-host | user-provided value |
168+
| test.ps1:269:7:269:10 | $y | test.ps1:265:14:265:36 | Call to read-host | test.ps1:269:7:269:10 | $y | This command depends on a $@. | test.ps1:265:14:265:36 | Call to read-host | user-provided value |

powershell/ql/test/query-tests/security/cwe-078/CommandInjection/test.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ Invoke-ExpandStringInjection2 -UserInput $input
186186
Invoke-InvokeExpressionInjectionCmdletBinding -userInput $input
187187
Invoke-StartProcessInjection -UserInput $input
188188

189+
function Get-NugetHardcoded
190+
{
191+
Invoke-WebRequest "https://somehardcodedwebsite.org/somefile.exe" -OutFile $webRequestResultSafe
192+
return $webRequestResultSafe
193+
}
194+
195+
$nugetPathSafe = Get-NugetHardcoded
196+
. $nugetPathSafe
197+
189198
#typed input
190199
function Invoke-InvokeExpressionInjectionSafe1
191200
{

0 commit comments

Comments
 (0)