Skip to content

Commit 1c7d63a

Browse files
committed
Swift: Model sinks explicitly with models-as-data.
1 parent 7b9b96d commit 1c7d63a

File tree

3 files changed

+52
-174
lines changed

3 files changed

+52
-174
lines changed

swift/ql/lib/codeql/swift/security/CommandInjectionExtensions.qll

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,28 @@ private class CommandInjectionArrayAdditionalFlowStep extends CommandInjectionAd
4242
}
4343
}
4444

45-
/**
46-
* A `DataFlow::Node` that is written into a `Process` object.
47-
*/
48-
private class ProcessSink extends CommandInjectionSink instanceof DataFlow::Node {
49-
ProcessSink() {
50-
// any write into a class derived from `Process` is a sink. For
51-
// example in `Process.launchPath = sensitive` the post-update node corresponding
52-
// with `Process.launchPath` is a sink.
53-
exists(NominalType t, Expr e |
54-
t.getABaseType*().getUnderlyingType().getName() = "Process" and
55-
this.(DataFlow::PostUpdateNode).getPreUpdateNode().asExpr() = e and
56-
e.getFullyConverted().getType() = t and
57-
not e.(DeclRefExpr).getDecl() instanceof SelfParamDecl
58-
)
59-
}
60-
}
61-
6245
/**
6346
* A sink defined in a CSV model.
6447
*/
6548
private class DefaultCommandInjectionSink extends CommandInjectionSink {
6649
DefaultCommandInjectionSink() { sinkNode(this, "command-injection") }
6750
}
51+
52+
private class CommandInjectionSinks extends SinkModelCsv {
53+
override predicate row(string row) {
54+
row =
55+
[
56+
";Process;true;run(_:arguments:terminationHandler:);;;Argument[0..1];command-injection",
57+
";Process;true;launchedProcess(launchPath:arguments:);;;Argument[0..1];command-injection",
58+
";Process;true;arguments;;;PostUpdate;command-injection",
59+
";Process;true;currentDirectory;;;PostUpdate;command-injection",
60+
";Process;true;environment;;;PostUpdate;command-injection",
61+
";Process;true;executableURL;;;PostUpdate;command-injection",
62+
";Process;true;standardError;;;PostUpdate;command-injection",
63+
";Process;true;standardInput;;;PostUpdate;command-injection",
64+
";Process;true;standardOutput;;;PostUpdate;command-injection",
65+
";Process;true;currentDirectoryPath;;;PostUpdate;command-injection",
66+
";Process;true;launchPath;;;PostUpdate;command-injection",
67+
]
68+
}
69+
}

0 commit comments

Comments
 (0)