Skip to content

Commit 4b7023c

Browse files
authored
Merge pull request #23080 from owen-mc/go/insecure-tls-fp
Go: Fix handling of default version in `go/insecure-tls`
2 parents 3f66891 + 7094a34 commit 4b7023c

6 files changed

Lines changed: 257 additions & 85 deletions

File tree

‎go/ql/src/Security/CWE-327/InsecureTLS.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func main() {}
99
func insecureMinMaxTlsVersion() {
1010
{
1111
config := &tls.Config{}
12-
config.MinVersion = 0 // BAD: Setting the MinVersion to 0 equals to choosing the lowest supported version (i.e. SSL3.0)
12+
config.MinVersion = tls.VersionTLS10 // BAD: TLS 1.0 is a non-secure version of the protocol; it's not safe to use it as MinVersion.
1313
}
1414
{
1515
config := &tls.Config{}

‎go/ql/src/Security/CWE-327/InsecureTLS.qhelp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
Only use secure TLS versions (1.3 and 1.2) and avoid using insecure cipher suites
2424
(you can see a list here: https://golang.org/src/crypto/tls/cipher_suites.go#L81)
2525
</p>
26+
<p>
27+
A zero <code>MinVersion</code>, whether explicit or omitted, selects Go's default minimum
28+
TLS version. This is TLS 1.2 for clients since Go 1.18 and servers since Go 1.22.
29+
When using older Go versions or compatibility settings that allow older TLS versions,
30+
set <code>MinVersion</code> to <code>tls.VersionTLS12</code> or higher explicitly.
31+
</p>
2632
</recommendation>
2733
<example>
2834
<p>

‎go/ql/src/Security/CWE-327/InsecureTLS.ql‎

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,17 @@ import semmle.go.security.InsecureFeatureFlag::InsecureFeatureFlag
1616
private import semmle.go.controlflow.Guards
1717

1818
/**
19-
* Holds if it is insecure to assign TLS version `val` named `name` to `tls.Config` field `fieldName`.
19+
* Holds if `val` is the integer value of an insecure TLS version constant named `name`.
2020
*/
21-
predicate isInsecureTlsVersion(int val, string name, string fieldName) {
22-
(fieldName = "MinVersion" or fieldName = "MaxVersion") and
23-
(
24-
// tls.VersionSSL30
25-
val = 768 and name = "VersionSSL30"
26-
or
27-
// tls.VersionTLS10
28-
val = 769 and name = "VersionTLS10"
29-
or
30-
// tls.VersionTLS11
31-
val = 770 and name = "VersionTLS11"
32-
or
33-
// Zero indicates the lowest available version setting for MinVersion,
34-
// or the highest available version setting for MaxVersion.
35-
val = 0 and name = "" and fieldName = "MinVersion"
36-
)
21+
predicate isInsecureTlsVersion(int val, string name) {
22+
// tls.VersionSSL30
23+
val = 768 and name = "VersionSSL30"
24+
or
25+
// tls.VersionTLS10
26+
val = 769 and name = "VersionTLS10"
27+
or
28+
// tls.VersionTLS11
29+
val = 770 and name = "VersionTLS11"
3730
}
3831

3932
/**
@@ -47,9 +40,9 @@ int getASecureTlsVersion() {
4740
* Returns integers that may represent a TLS version.
4841
*
4942
* Integer values corresponding to versions are defined at https://golang.org/pkg/crypto/tls/#pkg-constants
50-
* Zero means the default version; at the time of writing, TLS 1.0.
43+
* Zero selects the default version for the relevant field and is not tracked.
5144
*/
52-
int getATlsVersion() { result = getASecureTlsVersion() or isInsecureTlsVersion(result, _, _) }
45+
int getATlsVersion() { result = getASecureTlsVersion() or isInsecureTlsVersion(result, _) }
5346

5447
module TlsVersionFlowConfig implements DataFlow::ConfigSig {
5548
/**
@@ -81,29 +74,27 @@ module TlsVersionFlowConfig implements DataFlow::ConfigSig {
8174
module TlsVersionFlow = TaintTracking::Global<TlsVersionFlowConfig>;
8275

8376
/**
84-
* Holds if `config` exhibits a secure TLS version flowing from `source` to `sink`, which flows into `fld`.
77+
* Holds if a secure TLS version flows from `source` to `sink`.
8578
*/
86-
predicate secureTlsVersionFlow(DataFlow::Node source, DataFlow::Node sink, Field fld) {
79+
predicate secureTlsVersionFlow(DataFlow::Node source, DataFlow::Node sink) {
8780
exists(int version |
8881
TlsVersionFlow::flow(source, sink) and
8982
TlsVersionFlowConfig::intIsSource(source, version) and
90-
not isInsecureTlsVersion(version, _, fld.getName())
83+
not isInsecureTlsVersion(version, _)
9184
)
9285
}
9386

9487
/**
95-
* Holds if a secure TLS version reaches `sink`, which flows into `fld`.
88+
* Holds if a secure TLS version reaches `sink`.
9689
*/
97-
predicate secureTlsVersionFlowsToSink(DataFlow::Node sink, Field fld) {
98-
secureTlsVersionFlow(_, sink, fld)
99-
}
90+
predicate secureTlsVersionFlowsToSink(DataFlow::Node sink) { secureTlsVersionFlow(_, sink) }
10091

10192
/**
10293
* Holds if a secure TLS version may reach `accessPath`.`fld`
10394
*/
10495
predicate secureTlsVersionFlowsToField(SsaWithFields accessPath, Field fld) {
10596
exists(DataFlow::Node sink, DataFlow::Node base |
106-
secureTlsVersionFlow(_, sink, fld) and
97+
secureTlsVersionFlow(_, sink) and
10798
TlsVersionFlowConfig::isSink(sink, fld, base, _) and
10899
accessPath.getAUse() = base
109100
)
@@ -125,29 +116,22 @@ predicate isInsecureTlsVersionFlow(
125116
TlsVersionFlow::PathNode source, TlsVersionFlow::PathNode sink, string message,
126117
DataFlow::Node base
127118
) {
128-
exists(int version, Field fld |
119+
exists(int version, string name, Field fld |
129120
TlsVersionFlow::flowPath(source, sink) and
130121
TlsVersionFlowConfig::intIsSource(source.getNode(), version) and
131122
TlsVersionFlowConfig::isSink(sink.getNode(), fld, base, _) and
132-
isInsecureTlsVersion(version, _, fld.getName()) and
123+
isInsecureTlsVersion(version, name) and
133124
// Exclude cases where a secure TLS version can also flow to the same
134125
// sink, or to different sinks that refer to the same base and field,
135126
// which suggests a configurable security mode.
136-
not secureTlsVersionFlowsToSink(sink.getNode(), fld) and
127+
not secureTlsVersionFlowsToSink(sink.getNode()) and
137128
not exists(SsaWithFields insecureAccessPath, SsaWithFields secureAccessPath |
138129
nodeOrDeref(insecureAccessPath.getAUse()) = base and
139130
secureAccessPath = insecureAccessPath.similar()
140131
|
141132
secureTlsVersionFlowsToField(secureAccessPath, fld)
142-
)
143-
|
144-
version = 0 and
145-
message = "Using lowest TLS version for " + fld + "."
146-
or
147-
version != 0 and
148-
exists(string name | isInsecureTlsVersion(version, name, _) |
149-
message = "Using insecure TLS version " + name + " for " + fld + "."
150-
)
133+
) and
134+
message = "Using insecure TLS version " + name + " for " + fld + "."
151135
)
152136
}
153137

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The query `go/insecure-tls` ("Insecure TLS configuration") no longer flags a zero `tls.Config.MinVersion`, which selects Go's default minimum TLS version rather than an explicitly insecure version. Insecure `tls.Config.MaxVersion` values are also now reported even when `0` may also flow to `MaxVersion`.

0 commit comments

Comments
 (0)