Skip to content

Commit 0ad338f

Browse files
authored
Merge pull request github#14521 from geoffw0/defaultstep
Swift: Add CollectionContent to defaultImplicitTaintRead
2 parents 24e779b + c6ff429 commit 0ad338f

20 files changed

+190
-74
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
5+
* Collection content is now automatically read at taint flow sinks. This removes the need to define an `allowImplicitRead` predicate on data flow configurations where the sink might be an array, set or similar type with tainted contents. Where that step had not been defined, taint may find additional results now.

swift/ql/lib/codeql/swift/dataflow/internal/TaintTrackingPublic.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ predicate defaultImplicitTaintRead(DataFlow::Node node, DataFlow::ContentSet cs)
3737
cx.asNominalTypeDecl() = d and
3838
cs.getAReadContent().(DataFlow::Content::FieldContent).getField() = cx.getAMember()
3939
)
40+
or
41+
// We often expect taint to reach a sink inside `CollectionContent`, for example an array element
42+
// or pointer contents. It is convenient to have a default implicit read step for these cases rather
43+
// than implementing this step in a lot of separate `allowImplicitRead`s.
44+
cs.getAReadContent() instanceof DataFlow::Content::CollectionContent
4045
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ module CleartextLoggingConfig implements DataFlow::ConfigSig {
2525
predicate isAdditionalFlowStep(DataFlow::Node n1, DataFlow::Node n2) {
2626
any(CleartextLoggingAdditionalFlowStep s).step(n1, n2)
2727
}
28-
29-
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
30-
// flow out from collection content at the sink.
31-
isSink(node) and
32-
c.getAReadContent() instanceof DataFlow::Content::CollectionContent
33-
}
3428
}
3529

3630
/**

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ module CleartextStorageDatabaseConfig implements DataFlow::ConfigSig {
4545
isSink(node) and
4646
node.asExpr().getType().getUnderlyingType() instanceof DictionaryType and
4747
c.getAReadContent().(DataFlow::Content::TupleContent).getIndex() = 1
48-
or
49-
// flow out from array elements (and other collection content) at the sink,
50-
// for example in `database.allStatements(sql: "", arguments: [sensitive])`.
51-
isSink(node) and
52-
c.getAReadContent() instanceof DataFlow::Content::CollectionContent
5348
}
5449
}
5550

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ 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-
}
3226
}
3327

3428
/**

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ module ConstantPasswordConfig implements DataFlow::ConfigSig {
3030

3131
predicate isBarrier(DataFlow::Node node) { node instanceof ConstantPasswordBarrier }
3232

33+
predicate isBarrierIn(DataFlow::Node node) {
34+
// make sources barriers so that we only report the closest instance
35+
isSource(node)
36+
}
37+
3338
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
3439
any(ConstantPasswordAdditionalFlowStep s).step(nodeFrom, nodeTo)
3540
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ module ConstantSaltConfig implements DataFlow::ConfigSig {
3131

3232
predicate isBarrier(DataFlow::Node node) { node instanceof ConstantSaltBarrier }
3333

34+
predicate isBarrierIn(DataFlow::Node node) {
35+
// make sources barriers so that we only report the closest instance
36+
isSource(node)
37+
}
38+
3439
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
3540
any(ConstantSaltAdditionalFlowStep s).step(nodeFrom, nodeTo)
3641
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ module HardcodedKeyConfig implements DataFlow::ConfigSig {
3838

3939
predicate isBarrier(DataFlow::Node node) { node instanceof HardcodedEncryptionKeyBarrier }
4040

41-
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
42-
any(HardcodedEncryptionKeyAdditionalFlowStep s).step(nodeFrom, nodeTo)
41+
predicate isBarrierIn(DataFlow::Node node) {
42+
// make sources barriers so that we only report the closest instance
43+
isSource(node)
4344
}
4445

45-
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
46-
// flow out of collections at the sink
47-
isSink(node) and
48-
c.getAReadContent() instanceof DataFlow::Content::CollectionContent
46+
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
47+
any(HardcodedEncryptionKeyAdditionalFlowStep s).step(nodeFrom, nodeTo)
4948
}
5049
}
5150

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ module StaticInitializationVectorConfig implements DataFlow::ConfigSig {
3232

3333
predicate isBarrier(DataFlow::Node node) { node instanceof StaticInitializationVectorBarrier }
3434

35+
predicate isBarrierIn(DataFlow::Node node) {
36+
// make sources barriers so that we only report the closest instance
37+
isSource(node)
38+
}
39+
3540
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
3641
any(StaticInitializationVectorAdditionalFlowStep s).step(nodeFrom, nodeTo)
3742
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ module UnsafeJsEvalConfig implements DataFlow::ConfigSig {
2222
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
2323
any(UnsafeJsEvalAdditionalFlowStep s).step(nodeFrom, nodeTo)
2424
}
25-
26-
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
27-
// flow out from content a the sink
28-
(
29-
isSink(node)
30-
or
31-
isAdditionalFlowStep(node, _)
32-
) and
33-
c.getAReadContent() instanceof DataFlow::Content::CollectionContent
34-
}
3525
}
3626

3727
/**

0 commit comments

Comments
 (0)