@@ -16,20 +16,17 @@ import semmle.go.security.InsecureFeatureFlag::InsecureFeatureFlag
1616private 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- )
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"
3330}
3431
3532/**
@@ -45,7 +42,7 @@ int getASecureTlsVersion() {
4542 * Integer values corresponding to versions are defined at https://golang.org/pkg/crypto/tls/#pkg-constants
4643 * Zero selects the default version for the relevant field and is not tracked.
4744 */
48- int getATlsVersion ( ) { result = getASecureTlsVersion ( ) or isInsecureTlsVersion ( result , _, _ ) }
45+ int getATlsVersion ( ) { result = getASecureTlsVersion ( ) or isInsecureTlsVersion ( result , _) }
4946
5047module TlsVersionFlowConfig implements DataFlow:: ConfigSig {
5148 /**
@@ -77,29 +74,27 @@ module TlsVersionFlowConfig implements DataFlow::ConfigSig {
7774module TlsVersionFlow = TaintTracking:: Global< TlsVersionFlowConfig > ;
7875
7976/**
80- * 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`.
8178 */
82- predicate secureTlsVersionFlow ( DataFlow:: Node source , DataFlow:: Node sink , Field fld ) {
79+ predicate secureTlsVersionFlow ( DataFlow:: Node source , DataFlow:: Node sink ) {
8380 exists ( int version |
8481 TlsVersionFlow:: flow ( source , sink ) and
8582 TlsVersionFlowConfig:: intIsSource ( source , version ) and
86- not isInsecureTlsVersion ( version , _, fld . getName ( ) )
83+ not isInsecureTlsVersion ( version , _)
8784 )
8885}
8986
9087/**
91- * Holds if a secure TLS version reaches `sink`, which flows into `fld` .
88+ * Holds if a secure TLS version reaches `sink`.
9289 */
93- predicate secureTlsVersionFlowsToSink ( DataFlow:: Node sink , Field fld ) {
94- secureTlsVersionFlow ( _, sink , fld )
95- }
90+ predicate secureTlsVersionFlowsToSink ( DataFlow:: Node sink ) { secureTlsVersionFlow ( _, sink ) }
9691
9792/**
9893 * Holds if a secure TLS version may reach `accessPath`.`fld`
9994 */
10095predicate secureTlsVersionFlowsToField ( SsaWithFields accessPath , Field fld ) {
10196 exists ( DataFlow:: Node sink , DataFlow:: Node base |
102- secureTlsVersionFlow ( _, sink , fld ) and
97+ secureTlsVersionFlow ( _, sink ) and
10398 TlsVersionFlowConfig:: isSink ( sink , fld , base , _) and
10499 accessPath .getAUse ( ) = base
105100 )
@@ -121,25 +116,22 @@ predicate isInsecureTlsVersionFlow(
121116 TlsVersionFlow:: PathNode source , TlsVersionFlow:: PathNode sink , string message ,
122117 DataFlow:: Node base
123118) {
124- exists ( int version , Field fld |
119+ exists ( int version , string name , Field fld |
125120 TlsVersionFlow:: flowPath ( source , sink ) and
126121 TlsVersionFlowConfig:: intIsSource ( source .getNode ( ) , version ) and
127122 TlsVersionFlowConfig:: isSink ( sink .getNode ( ) , fld , base , _) and
128- isInsecureTlsVersion ( version , _ , fld . getName ( ) ) and
123+ isInsecureTlsVersion ( version , name ) and
129124 // Exclude cases where a secure TLS version can also flow to the same
130125 // sink, or to different sinks that refer to the same base and field,
131126 // which suggests a configurable security mode.
132- not secureTlsVersionFlowsToSink ( sink .getNode ( ) , fld ) and
127+ not secureTlsVersionFlowsToSink ( sink .getNode ( ) ) and
133128 not exists ( SsaWithFields insecureAccessPath , SsaWithFields secureAccessPath |
134129 nodeOrDeref ( insecureAccessPath .getAUse ( ) ) = base and
135130 secureAccessPath = insecureAccessPath .similar ( )
136131 |
137132 secureTlsVersionFlowsToField ( secureAccessPath , fld )
138- )
139- |
140- exists ( string name | isInsecureTlsVersion ( version , name , _) |
141- message = "Using insecure TLS version " + name + " for " + fld + "."
142- )
133+ ) and
134+ message = "Using insecure TLS version " + name + " for " + fld + "."
143135 )
144136}
145137
0 commit comments