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

Commit 34c8cc5

Browse files
committed
Improve documentation and function naming
1 parent 17200a8 commit 34c8cc5

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ predicate isTestFile(DataFlow::Node node) {
3434
)
3535
}
3636

37+
/**
38+
* Holds if it is insecure to assign TLS version `val` named `named` to `tls.Config` field `fieldName`
39+
*/
3740
predicate isInsecureTlsVersion(int val, string name, string fieldName) {
3841
(fieldName = "MinVersion" or fieldName = "MaxVersion") and
3942
// tls.VersionSSL30
@@ -103,11 +106,17 @@ predicate isReturnedWithError(DataFlow::Node node) {
103106
class TlsVersionFlowConfig extends TaintTracking::Configuration {
104107
TlsVersionFlowConfig() { this = "TlsVersionFlowConfig" }
105108

109+
/**
110+
* Holds if `source` is a TLS version source yielding value `val`.
111+
*/
106112
predicate isSource(DataFlow::Node source, int val) {
107113
val = source.getIntValue() and
108114
not isReturnedWithError(source)
109115
}
110116

117+
/**
118+
* Holds if `fieldWrite` writes `sink` to `base`.`fld`, where `fld` is a TLS version field.
119+
*/
111120
predicate isSink(DataFlow::Node sink, Field fld, DataFlow::Node base, Write fieldWrite) {
112121
fld.hasQualifiedName("crypto/tls", "Config", ["MinVersion", "MaxVersion"]) and
113122
fieldWrite = fld.getAWrite() and
@@ -162,9 +171,13 @@ DataFlow::Node nodeOrDeref(DataFlow::Node node) {
162171
}
163172

164173
/**
165-
* Find insecure TLS versions.
174+
* Holds if an insecure TLS version flows from `source` to `sink`, which is in turn written
175+
* to a field of `base`. `message` describes the specific problem found.
176+
*
177+
* Contexts suggesting an intentionally insecure or legacy configuration are excluded (see
178+
* `nodeSuggestsOldVersion`), as are fields that may conditionally receive a modern TLS version.
166179
*/
167-
query predicate checkTlsVersions(
180+
predicate isInsecureTlsVersionFlow(
168181
DataFlow::PathNode source, DataFlow::PathNode sink, string message, DataFlow::Node base
169182
) {
170183
exists(TlsVersionFlowConfig cfg, int version, Field fld |
@@ -201,6 +214,9 @@ query predicate checkTlsVersions(
201214
class TlsInsecureCipherSuitesFlowConfig extends TaintTracking::Configuration {
202215
TlsInsecureCipherSuitesFlowConfig() { this = "TlsInsecureCipherSuitesFlowConfig" }
203216

217+
/**
218+
* Holds if `source` reads an insecure TLS cipher suite named `suiteName`.
219+
*/
204220
predicate isSourceValueEntity(DataFlow::Node source, string suiteName) {
205221
exists(DataFlow::ValueEntity val |
206222
val.hasQualifiedName("crypto/tls", suiteName) and
@@ -214,6 +230,9 @@ class TlsInsecureCipherSuitesFlowConfig extends TaintTracking::Configuration {
214230
)
215231
}
216232

233+
/**
234+
* Holds if `source` represents the result of `tls.InsecureCipherSuites()`.
235+
*/
217236
predicate isSourceInsecureCipherSuites(DataFlow::Node source) {
218237
exists(Function insecureCipherSuites |
219238
insecureCipherSuites.hasQualifiedName("crypto/tls", "InsecureCipherSuites")
@@ -229,6 +248,10 @@ class TlsInsecureCipherSuitesFlowConfig extends TaintTracking::Configuration {
229248
isSourceValueEntity(source, _)
230249
}
231250

251+
/**
252+
* Holds if `fieldWrite` writes `sink` to `base`.`fld`, and `fld` is `tls.Config.CipherSuites`,
253+
* and no parent of `base` is named suggesting an intentionally insecure configuration.
254+
*/
232255
predicate isSink(DataFlow::Node sink, Field fld, DataFlow::Node base, Write fieldWrite) {
233256
fld.hasQualifiedName("crypto/tls", "Config", "CipherSuites") and
234257
fieldWrite = fld.getAWrite() and
@@ -249,11 +272,11 @@ class TlsInsecureCipherSuitesFlowConfig extends TaintTracking::Configuration {
249272
}
250273

251274
/**
252-
* Find insecure TLS cipher suites.
275+
* Holds if an insecure TLS cipher suite flows from `source` to `sink`, where `sink`
276+
* is written to the CipherSuites list of a `tls.Config` instance. `message` describes
277+
* the exact problem found.
253278
*/
254-
predicate checkTlsInsecureCipherSuites(
255-
DataFlow::PathNode source, DataFlow::PathNode sink, string message
256-
) {
279+
predicate isInsecureTlsCipherFlow(DataFlow::PathNode source, DataFlow::PathNode sink, string message) {
257280
exists(TlsInsecureCipherSuitesFlowConfig cfg | cfg.hasFlowPath(source, sink) |
258281
exists(string name | cfg.isSourceValueEntity(source.getNode(), name) |
259282
message = "Use of an insecure cipher suite: " + name + "."
@@ -267,12 +290,12 @@ predicate checkTlsInsecureCipherSuites(
267290
from DataFlow::PathNode source, DataFlow::PathNode sink, string message
268291
where
269292
(
270-
checkTlsVersions(source, sink, message, _) or
271-
checkTlsInsecureCipherSuites(source, sink, message)
293+
isInsecureTlsVersionFlow(source, sink, message, _) or
294+
isInsecureTlsCipherFlow(source, sink, message)
272295
) and
273296
// Exclude sinks guarded by a feature flag
274297
not getAFeatureFlagCheck().dominatesNode(sink.getNode().asInstruction()) and
275-
// Exclude results in functions whose name documents the insecurity
298+
// Exclude results in functions whose name documents insecurity
276299
not exists(FuncDef fn | fn = sink.getNode().asInstruction().getRoot() |
277300
isFeatureFlagName(fn.getEnclosingFunction*().getName()) or
278301
isOldVersionName(fn.getEnclosingFunction*().getName())

0 commit comments

Comments
 (0)