Skip to content

Commit f8207fa

Browse files
committed
PS: Add a testcase to demonstrate flow through Join-String.
1 parent ebb91dc commit f8207fa

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

powershell/ql/test/library-tests/dataflow/local/taint.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
| file://:0:0:0:0 | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | file://:0:0:0:0 | [summary] to write: ReturnValue in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] |
21
| test.ps1:1:1:1:3 | a1 | test.ps1:2:6:2:8 | a1 |
32
| test.ps1:1:1:24:22 | implicit unwrapping of {...} | test.ps1:1:1:24:22 | return value for {...} |
43
| test.ps1:1:1:24:22 | pre-return value for {...} | test.ps1:1:1:24:22 | implicit unwrapping of {...} |

powershell/ql/test/library-tests/dataflow/local/taint.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ import semmle.code.powershell.dataflow.TaintTracking
33
import semmle.code.powershell.dataflow.DataFlow
44

55
from DataFlow::Node pred, DataFlow::Node succ
6-
where TaintTracking::localTaintStep(pred, succ)
7-
select pred, succ
6+
where
7+
TaintTracking::localTaintStep(pred, succ) and
8+
pred.getLocation().getFile().getAbsolutePath() != ""
9+
select pred, succ
Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,50 @@
11
models
22
edges
3-
| file://:0:0:0:0 | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | file://:0:0:0:0 | [summary] to write: ReturnValue in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | provenance | |
3+
| file://:0:0:0:0 | [summary param] pipeline in microsoft.powershell.utility!;Method[join-string] [element 0] | file://:0:0:0:0 | [summary] read: Argument[pipeline].Element[?] in microsoft.powershell.utility!;Method[join-string] | provenance | |
4+
| file://:0:0:0:0 | [summary param] pipeline in microsoft.powershell.utility!;Method[join-string] [element 1] | file://:0:0:0:0 | [summary] read: Argument[pipeline].Element[?] in microsoft.powershell.utility!;Method[join-string] | provenance | |
5+
| file://:0:0:0:0 | [summary param] pos(0, {}) in system.management.automation.language.codegeneration!;Method[escapesinglequotedstringcontent] | file://:0:0:0:0 | [summary] to write: ReturnValue in system.management.automation.language.codegeneration!;Method[escapesinglequotedstringcontent] | provenance | |
6+
| file://:0:0:0:0 | [summary] read: Argument[pipeline].Element[?] in microsoft.powershell.utility!;Method[join-string] | file://:0:0:0:0 | [summary] to write: ReturnValue in microsoft.powershell.utility!;Method[join-string] | provenance | |
7+
| file://:0:0:0:0 | [summary] read: Argument[pipeline].Element[?] in microsoft.powershell.utility!;Method[join-string] | file://:0:0:0:0 | [summary] to write: ReturnValue in microsoft.powershell.utility!;Method[join-string] | provenance | |
48
| test.ps1:1:6:1:15 | Call to Source | test.ps1:2:94:2:95 | x | provenance | |
59
| test.ps1:2:6:2:96 | Call to EscapeSingleQuotedStringContent | test.ps1:3:6:3:7 | y | provenance | |
6-
| test.ps1:2:94:2:95 | x | file://:0:0:0:0 | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | provenance | |
10+
| test.ps1:2:94:2:95 | x | file://:0:0:0:0 | [summary param] pos(0, {}) in system.management.automation.language.codegeneration!;Method[escapesinglequotedstringcontent] | provenance | |
711
| test.ps1:2:94:2:95 | x | test.ps1:2:6:2:96 | Call to EscapeSingleQuotedStringContent | provenance | |
12+
| test.ps1:5:6:5:15 | Call to Source | test.ps1:7:6:7:7 | x | provenance | |
13+
| test.ps1:6:6:6:15 | Call to Source | test.ps1:7:10:7:11 | y | provenance | |
14+
| test.ps1:7:6:7:7 | x | test.ps1:7:6:7:11 | ...,... [element 0] | provenance | |
15+
| test.ps1:7:6:7:11 | ...,... [element 0] | file://:0:0:0:0 | [summary param] pipeline in microsoft.powershell.utility!;Method[join-string] [element 0] | provenance | |
16+
| test.ps1:7:6:7:11 | ...,... [element 0] | test.ps1:7:15:7:25 | Call to Join-String | provenance | |
17+
| test.ps1:7:6:7:11 | ...,... [element 1] | file://:0:0:0:0 | [summary param] pipeline in microsoft.powershell.utility!;Method[join-string] [element 1] | provenance | |
18+
| test.ps1:7:6:7:11 | ...,... [element 1] | test.ps1:7:15:7:25 | Call to Join-String | provenance | |
19+
| test.ps1:7:10:7:11 | y | test.ps1:7:6:7:11 | ...,... [element 1] | provenance | |
20+
| test.ps1:7:15:7:25 | Call to Join-String | test.ps1:8:6:8:7 | z | provenance | |
821
nodes
9-
| file://:0:0:0:0 | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | semmle.label | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] |
10-
| file://:0:0:0:0 | [summary] to write: ReturnValue in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | semmle.label | [summary] to write: ReturnValue in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] |
22+
| file://:0:0:0:0 | [summary param] pipeline in microsoft.powershell.utility!;Method[join-string] [element 0] | semmle.label | [summary param] pipeline in microsoft.powershell.utility!;Method[join-string] [element 0] |
23+
| file://:0:0:0:0 | [summary param] pipeline in microsoft.powershell.utility!;Method[join-string] [element 1] | semmle.label | [summary param] pipeline in microsoft.powershell.utility!;Method[join-string] [element 1] |
24+
| file://:0:0:0:0 | [summary param] pos(0, {}) in system.management.automation.language.codegeneration!;Method[escapesinglequotedstringcontent] | semmle.label | [summary param] pos(0, {}) in system.management.automation.language.codegeneration!;Method[escapesinglequotedstringcontent] |
25+
| file://:0:0:0:0 | [summary] read: Argument[pipeline].Element[?] in microsoft.powershell.utility!;Method[join-string] | semmle.label | [summary] read: Argument[pipeline].Element[?] in microsoft.powershell.utility!;Method[join-string] |
26+
| file://:0:0:0:0 | [summary] read: Argument[pipeline].Element[?] in microsoft.powershell.utility!;Method[join-string] | semmle.label | [summary] read: Argument[pipeline].Element[?] in microsoft.powershell.utility!;Method[join-string] |
27+
| file://:0:0:0:0 | [summary] to write: ReturnValue in microsoft.powershell.utility!;Method[join-string] | semmle.label | [summary] to write: ReturnValue in microsoft.powershell.utility!;Method[join-string] |
28+
| file://:0:0:0:0 | [summary] to write: ReturnValue in microsoft.powershell.utility!;Method[join-string] | semmle.label | [summary] to write: ReturnValue in microsoft.powershell.utility!;Method[join-string] |
29+
| file://:0:0:0:0 | [summary] to write: ReturnValue in system.management.automation.language.codegeneration!;Method[escapesinglequotedstringcontent] | semmle.label | [summary] to write: ReturnValue in system.management.automation.language.codegeneration!;Method[escapesinglequotedstringcontent] |
1130
| test.ps1:1:6:1:15 | Call to Source | semmle.label | Call to Source |
1231
| test.ps1:2:6:2:96 | Call to EscapeSingleQuotedStringContent | semmle.label | Call to EscapeSingleQuotedStringContent |
1332
| test.ps1:2:94:2:95 | x | semmle.label | x |
1433
| test.ps1:3:6:3:7 | y | semmle.label | y |
34+
| test.ps1:5:6:5:15 | Call to Source | semmle.label | Call to Source |
35+
| test.ps1:6:6:6:15 | Call to Source | semmle.label | Call to Source |
36+
| test.ps1:7:6:7:7 | x | semmle.label | x |
37+
| test.ps1:7:6:7:11 | ...,... [element 0] | semmle.label | ...,... [element 0] |
38+
| test.ps1:7:6:7:11 | ...,... [element 1] | semmle.label | ...,... [element 1] |
39+
| test.ps1:7:10:7:11 | y | semmle.label | y |
40+
| test.ps1:7:15:7:25 | Call to Join-String | semmle.label | Call to Join-String |
41+
| test.ps1:8:6:8:7 | z | semmle.label | z |
1542
subpaths
16-
| test.ps1:2:94:2:95 | x | file://:0:0:0:0 | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | file://:0:0:0:0 | [summary] to write: ReturnValue in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | test.ps1:2:6:2:96 | Call to EscapeSingleQuotedStringContent |
43+
| test.ps1:2:94:2:95 | x | file://:0:0:0:0 | [summary param] pos(0, {}) in system.management.automation.language.codegeneration!;Method[escapesinglequotedstringcontent] | file://:0:0:0:0 | [summary] to write: ReturnValue in system.management.automation.language.codegeneration!;Method[escapesinglequotedstringcontent] | test.ps1:2:6:2:96 | Call to EscapeSingleQuotedStringContent |
44+
| test.ps1:7:6:7:11 | ...,... [element 0] | file://:0:0:0:0 | [summary param] pipeline in microsoft.powershell.utility!;Method[join-string] [element 0] | file://:0:0:0:0 | [summary] to write: ReturnValue in microsoft.powershell.utility!;Method[join-string] | test.ps1:7:15:7:25 | Call to Join-String |
45+
| test.ps1:7:6:7:11 | ...,... [element 1] | file://:0:0:0:0 | [summary param] pipeline in microsoft.powershell.utility!;Method[join-string] [element 1] | file://:0:0:0:0 | [summary] to write: ReturnValue in microsoft.powershell.utility!;Method[join-string] | test.ps1:7:15:7:25 | Call to Join-String |
1746
testFailures
1847
#select
1948
| test.ps1:3:6:3:7 | y | test.ps1:1:6:1:15 | Call to Source | test.ps1:3:6:3:7 | y | $@ | test.ps1:1:6:1:15 | Call to Source | Call to Source |
49+
| test.ps1:8:6:8:7 | z | test.ps1:5:6:5:15 | Call to Source | test.ps1:8:6:8:7 | z | $@ | test.ps1:5:6:5:15 | Call to Source | Call to Source |
50+
| test.ps1:8:6:8:7 | z | test.ps1:6:6:6:15 | Call to Source | test.ps1:8:6:8:7 | z | $@ | test.ps1:6:6:6:15 | Call to Source | Call to Source |
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
$x = Source "1"
22
$y = [System.Management.Automation.Language.CodeGeneration]::EscapeSingleQuotedStringContent($x)
3-
Sink $y # $ hasTaintFlow=1
3+
Sink $y # $ hasTaintFlow=1
4+
5+
$x = Source "2"
6+
$y = Source "3"
7+
$z = $x, $y | Join-String
8+
Sink $z # $ hasTaintFlow=2 hasTaintFlow=3

0 commit comments

Comments
 (0)