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 {
3131 abstract class Sanitizer extends DataFlow:: Node { }
3232
3333 /** 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+
3540 override string getSourceType ( ) { result = "user-provided value" }
3641 }
3742
Original file line number Diff line number Diff line change 5454| test.ps1:172:42:172:47 | input | test.ps1:136:11:136:20 | userinput | provenance | |
5555| test.ps1:173:42:173:47 | input | test.ps1:144:11:144:20 | userinput | provenance | |
5656| 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 |
5758nodes
5859| test.ps1:3:11:3:20 | userinput | semmle.label | userinput |
5960| test.ps1:4:23:4:52 | Get-Process -Name $UserInput | semmle.label | Get-Process -Name $UserInput |
@@ -112,6 +113,8 @@ nodes
112113| test.ps1:173:42:173:47 | input | semmle.label | input |
113114| test.ps1:214:10:214:32 | Call to read-host | semmle.label | Call to read-host |
114115| 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 |
115118subpaths
116119#select
117120| 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
133136| 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 |
134137| 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 |
135138| 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)
215215 & unzip - o " $o " - d $d # GOOD
216216
217217 . " $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
218230}
You can’t perform that action at this time.
0 commit comments