@@ -16,24 +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- 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
5447module TlsVersionFlowConfig implements DataFlow:: ConfigSig {
5548 /**
@@ -81,29 +74,27 @@ module TlsVersionFlowConfig implements DataFlow::ConfigSig {
8174module 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 */
10495predicate 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
0 commit comments