11/**
22 * @name Insecure TLS configuration
33 * @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.
55 * @kind path-problem
66 * @problem.severity warning
77 * @precision very-high
@@ -15,12 +15,12 @@ import DataFlow::PathGraph
1515import semmle.go.security.InsecureFeatureFlag:: InsecureFeatureFlag
1616
1717/**
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`.
1919 */
2020predicate isInsecureTlsVersion ( int val , string name , string fieldName ) {
2121 ( fieldName = "MinVersion" or fieldName = "MaxVersion" ) and
22- // tls.VersionSSL30
2322 (
23+ // tls.VersionSSL30
2424 val = 768 and name = "VersionSSL30"
2525 or
2626 // tls.VersionTLS10
@@ -35,13 +35,20 @@ predicate isInsecureTlsVersion(int val, string name, string fieldName) {
3535 )
3636}
3737
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+
3845/**
3946 * Returns integers that may represent a TLS version.
4047 *
4148 * Integer values corresponding to versions are defined at https://golang.org/pkg/crypto/tls/#pkg-constants
4249 * Zero means the default version; at the time of writing, TLS 1.0.
4350 */
44- int getATlsVersion ( ) { result in [ 768 , 769 , 770 , 771 , 772 , 0 ] }
51+ int getATlsVersion ( ) { result = getASecureTlsVersion ( ) or isInsecureTlsVersion ( result , _ , _ ) }
4552
4653/**
4754 * Holds if `node` refers to a value returned alongside a non-nil error value.
@@ -52,8 +59,8 @@ predicate isReturnedWithError(DataFlow::Node node) {
5259 exists ( ReturnStmt ret |
5360 ret .getExpr ( 0 ) = node .asExpr ( ) and
5461 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`
5764 )
5865}
5966
@@ -106,7 +113,7 @@ predicate secureTlsVersionFlowsToSink(DataFlow::PathNode sink, Field fld) {
106113}
107114
108115/**
109- * Holds if a secure TLS version may reach `base `.`fld`
116+ * Holds if a secure TLS version may reach `accessPath `.`fld`
110117 */
111118predicate secureTlsVersionFlowsToField ( SsaWithFields accessPath , Field fld ) {
112119 exists (
0 commit comments