Skip to content

Commit 11aff55

Browse files
committed
Swift: Add default implicit read steps when selecting PostUpdateNodes as sinks.
1 parent e6c8428 commit 11aff55

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,14 @@ predicate localTaintStep = localTaintStepCached/2;
2626
* of `c` at sinks and inputs to additional taint steps.
2727
*/
2828
bindingset[node]
29-
predicate defaultImplicitTaintRead(DataFlow::Node node, DataFlow::ContentSet c) { none() }
29+
predicate defaultImplicitTaintRead(DataFlow::Node node, DataFlow::ContentSet cs) {
30+
// If a `PostUpdateNode` is specified as a sink, there's (almost) always a store step preceding it.
31+
// So when the node is a `PostUpdateNode` we allow any sequence of implicit read steps of an appropriate
32+
// type to make sure we arrive at the sink with an empty access path.
33+
exists(NominalTypeDecl d, Decl cx |
34+
node.(DataFlow::PostUpdateNode).getPreUpdateNode().asExpr().getType() =
35+
d.getType().getABaseType*() and
36+
cx.asNominalTypeDecl() = d and
37+
cs.getAReadContent().(DataFlow::Content::FieldContent).getField() = cx.getAMember()
38+
)
39+
}

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ module InsecureTlsConfig implements DataFlow::ConfigSig {
2222
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
2323
any(InsecureTlsExtensionsAdditionalTaintStep s).step(nodeFrom, nodeTo)
2424
}
25-
26-
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
27-
// flow out from fields of an `URLSessionConfiguration` at the sink,
28-
// for example in `sessionConfig.tlsMaximumSupportedProtocolVersion = tls_protocol_version_t.TLSv10`.
29-
isSink(node) and
30-
exists(NominalTypeDecl d, Decl cx |
31-
d.getType().getABaseType*().getUnderlyingType().getName() = "URLSessionConfiguration" and
32-
cx.asNominalTypeDecl() = d and
33-
c.getAReadContent().(DataFlow::Content::FieldContent).getField() = cx.getAMember()
34-
)
35-
}
3625
}
3726

3827
module InsecureTlsFlow = TaintTracking::Global<InsecureTlsConfig>;

swift/ql/test/query-tests/Security/CWE-757/InsecureTLS.expected

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ edges
4949
| InsecureTLS.swift:181:53:181:76 | .TLSv10 : | InsecureTLS.swift:19:7:19:7 | value : |
5050
| InsecureTLS.swift:181:53:181:76 | .TLSv10 : | InsecureTLS.swift:181:3:181:9 | [post] getter for .config |
5151
| InsecureTLS.swift:181:53:181:76 | .TLSv10 : | InsecureTLS.swift:181:3:181:9 | [post] getter for .config [tlsMinimumSupportedProtocolVersion] : |
52-
| InsecureTLS.swift:185:20:185:36 | withMinVersion : | InsecureTLS.swift:187:42:187:42 | withMinVersion : |
53-
| InsecureTLS.swift:187:5:187:5 | [post] self [tlsMinimumSupportedProtocolVersion] : | InsecureTLS.swift:187:5:187:5 | [post] self |
54-
| InsecureTLS.swift:187:42:187:42 | withMinVersion : | InsecureTLS.swift:187:5:187:5 | [post] self [tlsMinimumSupportedProtocolVersion] : |
55-
| InsecureTLS.swift:193:51:193:74 | .TLSv10 : | InsecureTLS.swift:185:20:185:36 | withMinVersion : |
5652
| file://:0:0:0:0 | [post] self [tlsMaximumSupportedProtocolVersion] : | file://:0:0:0:0 | [post] self |
5753
| file://:0:0:0:0 | [post] self [tlsMaximumSupportedProtocolVersion] : | file://:0:0:0:0 | [post] self : |
5854
| file://:0:0:0:0 | [post] self [tlsMaximumSupportedProtocol] : | file://:0:0:0:0 | [post] self |
@@ -107,11 +103,6 @@ nodes
107103
| InsecureTLS.swift:181:3:181:9 | [post] getter for .config | semmle.label | [post] getter for .config |
108104
| InsecureTLS.swift:181:3:181:9 | [post] getter for .config [tlsMinimumSupportedProtocolVersion] : | semmle.label | [post] getter for .config [tlsMinimumSupportedProtocolVersion] : |
109105
| InsecureTLS.swift:181:53:181:76 | .TLSv10 : | semmle.label | .TLSv10 : |
110-
| InsecureTLS.swift:185:20:185:36 | withMinVersion : | semmle.label | withMinVersion : |
111-
| InsecureTLS.swift:187:5:187:5 | [post] self | semmle.label | [post] self |
112-
| InsecureTLS.swift:187:5:187:5 | [post] self [tlsMinimumSupportedProtocolVersion] : | semmle.label | [post] self [tlsMinimumSupportedProtocolVersion] : |
113-
| InsecureTLS.swift:187:42:187:42 | withMinVersion : | semmle.label | withMinVersion : |
114-
| InsecureTLS.swift:193:51:193:74 | .TLSv10 : | semmle.label | .TLSv10 : |
115106
| file://:0:0:0:0 | .TLSVersion : | semmle.label | .TLSVersion : |
116107
| file://:0:0:0:0 | [post] self | semmle.label | [post] self |
117108
| file://:0:0:0:0 | [post] self | semmle.label | [post] self |
@@ -163,7 +154,6 @@ subpaths
163154
| InsecureTLS.swift:122:3:122:3 | [post] config | InsecureTLS.swift:127:25:127:48 | .TLSv11 : | InsecureTLS.swift:122:3:122:3 | [post] config | This TLS configuration is insecure. |
164155
| InsecureTLS.swift:165:3:165:3 | [post] config | InsecureTLS.swift:163:20:163:43 | .TLSv10 : | InsecureTLS.swift:165:3:165:3 | [post] config | This TLS configuration is insecure. |
165156
| InsecureTLS.swift:181:3:181:9 | [post] getter for .config | InsecureTLS.swift:181:53:181:76 | .TLSv10 : | InsecureTLS.swift:181:3:181:9 | [post] getter for .config | This TLS configuration is insecure. |
166-
| InsecureTLS.swift:187:5:187:5 | [post] self | InsecureTLS.swift:193:51:193:74 | .TLSv10 : | InsecureTLS.swift:187:5:187:5 | [post] self | This TLS configuration is insecure. |
167157
| file://:0:0:0:0 | [post] self | InsecureTLS.swift:40:47:40:70 | .TLSv10 : | file://:0:0:0:0 | [post] self | This TLS configuration is insecure. |
168158
| file://:0:0:0:0 | [post] self | InsecureTLS.swift:45:47:45:70 | .TLSv11 : | file://:0:0:0:0 | [post] self | This TLS configuration is insecure. |
169159
| file://:0:0:0:0 | [post] self | InsecureTLS.swift:57:47:57:70 | .TLSv10 : | file://:0:0:0:0 | [post] self | This TLS configuration is insecure. |

0 commit comments

Comments
 (0)