File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed
lib/semmle/code/powershell/security
test/query-tests/security/cwe-078/CommandInjection Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,12 @@ module CommandInjection {
31
31
abstract class Sanitizer extends DataFlow:: Node { }
32
32
33
33
/** A source of user input, considered as a flow source for command injection. */
34
- class FlowSourceAsSource extends Source instanceof SourceNode {
34
+ class FlowSourceAsSource extends Source {
35
+ FlowSourceAsSource ( ) {
36
+ this instanceof SourceNode and
37
+ not this instanceof EnvironmentVariableSource
38
+ }
39
+
35
40
override string getSourceType ( ) { result = "user-provided value" }
36
41
}
37
42
Original file line number Diff line number Diff line change 54
54
| test.ps1:172:42:172:47 | input | test.ps1:136:11:136:20 | userinput | provenance | |
55
55
| test.ps1:173:42:173:47 | input | test.ps1:144:11:144:20 | userinput | provenance | |
56
56
| test.ps1:214:10:214:32 | Call to read-host | test.ps1:217:7:217:10 | $o | provenance | Src:MaD:0 |
57
+ | test.ps1:225:14:225:36 | Call to read-host | test.ps1:229:7:229:10 | $y | provenance | Src:MaD:0 |
57
58
nodes
58
59
| test.ps1:3:11:3:20 | userinput | semmle.label | userinput |
59
60
| test.ps1:4:23:4:52 | Get-Process -Name $UserInput | semmle.label | Get-Process -Name $UserInput |
@@ -112,6 +113,8 @@ nodes
112
113
| test.ps1:173:42:173:47 | input | semmle.label | input |
113
114
| test.ps1:214:10:214:32 | Call to read-host | semmle.label | Call to read-host |
114
115
| test.ps1:217:7:217:10 | $o | semmle.label | $o |
116
+ | test.ps1:225:14:225:36 | Call to read-host | semmle.label | Call to read-host |
117
+ | test.ps1:229:7:229:10 | $y | semmle.label | $y |
115
118
subpaths
116
119
#select
117
120
| test.ps1:4:23:4:52 | Get-Process -Name $UserInput | test.ps1:152:10:152:32 | Call to read-host | test.ps1:4:23:4:52 | Get-Process -Name $UserInput | This command depends on a $@. | test.ps1:152:10:152:32 | Call to read-host | user-provided value |
@@ -133,3 +136,4 @@ subpaths
133
136
| test.ps1:139:50:139:59 | UserInput | test.ps1:152:10:152:32 | Call to read-host | test.ps1:139:50:139:59 | UserInput | This command depends on a $@. | test.ps1:152:10:152:32 | Call to read-host | user-provided value |
134
137
| test.ps1:147:63:147:72 | UserInput | test.ps1:152:10:152:32 | Call to read-host | test.ps1:147:63:147:72 | UserInput | This command depends on a $@. | test.ps1:152:10:152:32 | Call to read-host | user-provided value |
135
138
| test.ps1:217:7:217:10 | $o | test.ps1:214:10:214:32 | Call to read-host | test.ps1:217:7:217:10 | $o | This command depends on a $@. | test.ps1:214:10:214:32 | Call to read-host | user-provided value |
139
+ | test.ps1:229:7:229:10 | $y | test.ps1:225:14:225:36 | Call to read-host | test.ps1:229:7:229:10 | $y | This command depends on a $@. | test.ps1:225:14:225:36 | Call to read-host | user-provided value |
Original file line number Diff line number Diff line change @@ -215,4 +215,16 @@ function false-positive-in-call-operator($d)
215
215
& unzip - o " $o " - d $d # GOOD
216
216
217
217
. " $o " # BAD
218
+ }
219
+
220
+ function flow-through-env-var () {
221
+ $x = $env: foo
222
+
223
+ . " $x " # GOOD # we don't consider environment vars flow sources
224
+
225
+ $input = Read-Host " enter input"
226
+ $env: bar = $input
227
+
228
+ $y = $env: bar
229
+ . " $y " # BAD # but we have flow through them
218
230
}
You can’t perform that action at this time.
0 commit comments