1
1
/**
2
2
* @name Insecure TLS configuration
3
3
* @description If an application supports insecure TLS versions or ciphers, it may be vulnerable to
4
- * man -in-the-middle and other attacks.
4
+ * machine -in-the-middle and other attacks.
5
5
* @kind path-problem
6
6
* @problem.severity warning
7
7
* @precision very-high
@@ -15,12 +15,12 @@ import DataFlow::PathGraph
15
15
import semmle.go.security.InsecureFeatureFlag:: InsecureFeatureFlag
16
16
17
17
/**
18
- * Holds if it is insecure to assign TLS version `val` named `named ` to `tls.Config` field `fieldName`
18
+ * Holds if it is insecure to assign TLS version `val` named `name ` to `tls.Config` field `fieldName`.
19
19
*/
20
20
predicate isInsecureTlsVersion ( int val , string name , string fieldName ) {
21
21
( fieldName = "MinVersion" or fieldName = "MaxVersion" ) and
22
- // tls.VersionSSL30
23
22
(
23
+ // tls.VersionSSL30
24
24
val = 768 and name = "VersionSSL30"
25
25
or
26
26
// tls.VersionTLS10
@@ -35,13 +35,20 @@ predicate isInsecureTlsVersion(int val, string name, string fieldName) {
35
35
)
36
36
}
37
37
38
+ /**
39
+ * Returns integers that may represent a secure TLS version.
40
+ */
41
+ int getASecureTlsVersion ( ) {
42
+ result in [ 771 , 772 ] // TLS 1.2 and 1.3 respectively
43
+ }
44
+
38
45
/**
39
46
* Returns integers that may represent a TLS version.
40
47
*
41
48
* Integer values corresponding to versions are defined at https://golang.org/pkg/crypto/tls/#pkg-constants
42
49
* Zero means the default version; at the time of writing, TLS 1.0.
43
50
*/
44
- int getATlsVersion ( ) { result in [ 768 , 769 , 770 , 771 , 772 , 0 ] }
51
+ int getATlsVersion ( ) { result = getASecureTlsVersion ( ) or isInsecureTlsVersion ( result , _ , _ ) }
45
52
46
53
/**
47
54
* Holds if `node` refers to a value returned alongside a non-nil error value.
@@ -52,8 +59,8 @@ predicate isReturnedWithError(DataFlow::Node node) {
52
59
exists ( ReturnStmt ret |
53
60
ret .getExpr ( 0 ) = node .asExpr ( ) and
54
61
ret .getNumExpr ( ) = 2 and
55
- ret .getExpr ( 1 ) .getType ( ) .implements ( Builtin:: error ( ) .getType ( ) .getUnderlyingType ( ) ) and
56
- ret .getExpr ( 1 ) != Builtin :: nil ( ) . getAReference ( )
62
+ ret .getExpr ( 1 ) .getType ( ) .implements ( Builtin:: error ( ) .getType ( ) .getUnderlyingType ( ) )
63
+ // That last condition implies ret.getExpr(1) is non- nil, since nil doesn't implement `error`
57
64
)
58
65
}
59
66
@@ -106,7 +113,7 @@ predicate secureTlsVersionFlowsToSink(DataFlow::PathNode sink, Field fld) {
106
113
}
107
114
108
115
/**
109
- * Holds if a secure TLS version may reach `base `.`fld`
116
+ * Holds if a secure TLS version may reach `accessPath `.`fld`
110
117
*/
111
118
predicate secureTlsVersionFlowsToField ( SsaWithFields accessPath , Field fld ) {
112
119
exists (
0 commit comments