Skip to content

Commit c518f39

Browse files
authored
Merge pull request github#14357 from geoffw0/commandinject3
Swift: Replace two additional taint steps with implicit reads
2 parents 8224f17 + bbd3c66 commit c518f39

File tree

6 files changed

+296
-177
lines changed

6 files changed

+296
-177
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,9 @@ private class CleartextStorageDatabaseDefaultBarrier extends CleartextStorageDat
128128
/**
129129
* An additional taint step for cleartext database storage vulnerabilities.
130130
*/
131-
private class CleartextStorageDatabaseArrayAdditionalFlowStep extends CleartextStorageDatabaseAdditionalFlowStep
131+
private class CleartextStorageDatabaseFieldsAdditionalFlowStep extends CleartextStorageDatabaseAdditionalFlowStep
132132
{
133133
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
134-
// needed until we have proper content flow through arrays.
135-
exists(ArrayExpr arr |
136-
nodeFrom.asExpr() = arr.getAnElement() and
137-
nodeTo.asExpr() = arr
138-
)
139-
or
140134
// if an object is sensitive, its fields are always sensitive
141135
// (this is needed because the sensitive data sources are in a sense
142136
// approximate; for example we might identify `passwordBox` as a source,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ module CleartextStorageDatabaseConfig implements DataFlow::ConfigSig {
3939
cx.asNominalTypeDecl() = d and
4040
c.getAReadContent().(DataFlow::Content::FieldContent).getField() = cx.getAMember()
4141
)
42+
or
43+
// flow out from array elements of at the sink,
44+
// for example in `database.allStatements(sql: "", arguments: [sensitive])`.
45+
isSink(node) and
46+
c.getAReadContent() instanceof DataFlow::Content::CollectionContent
4247
}
4348
}
4449

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,6 @@ class CommandInjectionAdditionalFlowStep extends Unit {
2929
abstract predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo);
3030
}
3131

32-
/**
33-
* An additional taint step for command injection vulnerabilities.
34-
*/
35-
private class CommandInjectionArrayAdditionalFlowStep extends CommandInjectionAdditionalFlowStep {
36-
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
37-
// needed until we have proper content flow through arrays.
38-
exists(ArrayExpr arr |
39-
nodeFrom.asExpr() = arr.getAnElement() and
40-
nodeTo.asExpr() = arr
41-
)
42-
}
43-
}
44-
4532
/**
4633
* A sink defined in a CSV model.
4734
*/

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ module CommandInjectionConfig implements DataFlow::ConfigSig {
2323
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
2424
any(CommandInjectionAdditionalFlowStep s).step(nodeFrom, nodeTo)
2525
}
26+
27+
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
28+
// flow out from array elements of at the sink, for example in `task.arguments = [tainted]`.
29+
isSink(node) and
30+
c.getAReadContent() instanceof DataFlow::Content::CollectionContent
31+
}
2632
}
2733

2834
/**

0 commit comments

Comments
 (0)