Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 17200a8

Browse files
committed
Use SsaWithFields to find similar good-tls-version flows
Note: if accepted, merge this into a previous commit before submitting the PR
1 parent a7e549e commit 17200a8

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

ql/src/experimental/CWE-327/InsecureTLS.ql

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,43 +120,51 @@ class TlsVersionFlowConfig extends TaintTracking::Configuration {
120120
}
121121

122122
/**
123-
* Holds if a secure TLS version may reach `sink`, which writes to `base`.`fld`
123+
* Holds if `config` exhibits a secure TLS version flowing from `source` to `sink`, which flows into `fld`.
124124
*/
125-
predicate secureTlsVersionFlowsToSink(DataFlow::PathNode sink, Field fld, DataFlow::Node base) {
126-
exists(TlsVersionFlowConfig secureCfg, DataFlow::PathNode source, int version |
127-
secureCfg.hasFlowPath(source, sink) and
128-
secureCfg.isSink(sink.getNode(), fld, base, _) and
129-
secureCfg.isSource(source.getNode(), version) and
125+
predicate secureTlsVersionFlow(
126+
TlsVersionFlowConfig config, DataFlow::PathNode source, DataFlow::PathNode sink, Field fld
127+
) {
128+
exists(int version |
129+
config.hasFlowPath(source, sink) and
130+
config.isSource(source.getNode(), version) and
130131
not isInsecureTlsVersion(version, _, fld.getName())
131132
)
132133
}
133134

134135
/**
135-
* Holds if a secure TLS version may reach `baseEntity`.`fld`
136+
* Holds if a secure TLS version reaches `sink`, which flows into `fld`.
136137
*/
137-
predicate secureTlsVersionFlowsToEntity(ValueEntity baseEntity, Field fld) {
138-
exists(DataFlow::PathNode sink, DataFlow::Node base |
139-
secureTlsVersionFlowsToSink(sink, fld, base) and
140-
base.(DataFlow::ReadNode).reads(baseEntity)
141-
)
138+
predicate secureTlsVersionFlowsToSink(DataFlow::PathNode sink, Field fld) {
139+
secureTlsVersionFlow(_, _, sink, fld)
142140
}
143141

144142
/**
145143
* Holds if a secure TLS version may reach `base`.`fld`
146144
*/
147-
predicate secureTlsVersionFlowsToField(DataFlow::Node base, Field fld) {
148-
secureTlsVersionFlowsToSink(_, fld, base)
149-
or
150-
exists(ValueEntity baseEntity |
151-
base.(DataFlow::ReadNode).reads(baseEntity) and
152-
secureTlsVersionFlowsToEntity(baseEntity, fld)
145+
predicate secureTlsVersionFlowsToField(SsaWithFields accessPath, Field fld) {
146+
exists(
147+
TlsVersionFlowConfig config, DataFlow::PathNode source, DataFlow::PathNode sink,
148+
DataFlow::Node base
149+
|
150+
secureTlsVersionFlow(config, source, sink, fld) and
151+
config.isSink(sink.getNode(), fld, base, _) and
152+
accessPath.getAUse() = base
153153
)
154154
}
155155

156+
/**
157+
* Returns `node` or an implicit-deref node referring to it
158+
*/
159+
DataFlow::Node nodeOrDeref(DataFlow::Node node) {
160+
result = node or
161+
result.asInstruction() = IR::implicitDerefInstruction(node.asExpr())
162+
}
163+
156164
/**
157165
* Find insecure TLS versions.
158166
*/
159-
predicate checkTlsVersions(
167+
query predicate checkTlsVersions(
160168
DataFlow::PathNode source, DataFlow::PathNode sink, string message, DataFlow::Node base
161169
) {
162170
exists(TlsVersionFlowConfig cfg, int version, Field fld |
@@ -167,12 +175,13 @@ predicate checkTlsVersions(
167175
not nodeSuggestsOldVersion(base.asExpr().getParent*()) and
168176
// Exclude cases where a secure TLS version can also flow to the same
169177
// sink, or to different sinks that refer to the same base and field,
170-
// which suggests a configurable security mode. baseAlias is used because
171-
// isSink will return both implicit dereferences and the expression
172-
// accessed.
173-
not exists(DataFlow::Node baseAlias |
174-
cfg.isSink(sink.getNode(), fld, baseAlias, _) and
175-
secureTlsVersionFlowsToField(baseAlias, fld)
178+
// which suggests a configurable security mode.
179+
not secureTlsVersionFlowsToSink(sink, fld) and
180+
not exists(SsaWithFields insecureAccessPath, SsaWithFields secureAccessPath |
181+
nodeOrDeref(insecureAccessPath.getAUse()) = base and
182+
secureAccessPath = insecureAccessPath.similar()
183+
|
184+
secureTlsVersionFlowsToField(secureAccessPath, fld)
176185
)
177186
|
178187
version = 0 and

0 commit comments

Comments
 (0)