@@ -15,13 +15,11 @@ import go
1515/**
1616 * Flow of a `tls.Config` to a write to the `MinVersion` field.
1717 */
18- class TlsVersionFlowConfig extends TaintTracking:: Configuration {
19- TlsVersionFlowConfig ( ) { this = "TlsVersionFlowConfig" }
20-
18+ module TlsVersionConfig implements DataFlow:: ConfigSig {
2119 /**
2220 * Holds if `source` is a TLS.Config instance.
2321 */
24- override predicate isSource ( DataFlow:: Node source ) {
22+ predicate isSource ( DataFlow:: Node source ) {
2523 exists ( Variable v |
2624 configOrConfigPointer ( v .getType ( ) ) and
2725 source .asExpr ( ) = v .getAReference ( )
@@ -31,21 +29,21 @@ class TlsVersionFlowConfig extends TaintTracking::Configuration {
3129 /**
3230 * Holds if a write to `sink`.MinVersion exists.
3331 */
34- override predicate isSink ( DataFlow:: Node sink ) {
32+ predicate isSink ( DataFlow:: Node sink ) {
3533 exists ( Write fieldWrite , Field fld |
3634 fld .hasQualifiedName ( "crypto/tls" , "Config" , "MinVersion" ) and
3735 fieldWrite .writesField ( sink , fld , _)
3836 )
3937 }
4038}
39+ module TlsVersionFlow = TaintTracking:: Global< TlsVersionConfig > ;
40+
4141
4242/**
4343 * Flow of a `tls.Config` with `MinVersion` to a variable.
4444 */
45- class TlsConfigCreation extends TaintTracking:: Configuration {
46- TlsConfigCreation ( ) { this = "TlsConfigCreation" }
47-
48- predicate isSecure ( DataFlow:: Node source ) {
45+ module TlsConfigCreationConfig implements DataFlow:: ConfigSig {
46+ additional predicate isSecure ( DataFlow:: Node source ) {
4947 exists ( StructLit lit , Field fld |
5048 lit .getType ( ) .hasQualifiedName ( "crypto/tls" , "Config" ) and
5149 fld .hasQualifiedName ( "crypto/tls" , "Config" , "MinVersion" ) and
@@ -58,18 +56,19 @@ class TlsConfigCreation extends TaintTracking::Configuration {
5856 /**
5957 * Holds if `source` is a TLS.Config literal.
6058 */
61- override predicate isSource ( DataFlow:: Node source ) {
59+ predicate isSource ( DataFlow:: Node source ) {
6260 exists ( StructLit lit , Field fld |
6361 lit .getType ( ) .hasQualifiedName ( "crypto/tls" , "Config" ) and
6462 fld .hasQualifiedName ( "crypto/tls" , "Config" , "MinVersion" ) and
6563 source .asExpr ( ) = lit
6664 )
65+ and not isSecure ( source )
6766 }
6867
6968 /**
7069 * Holds if it is TLS.Config instance (a Variable).
7170 */
72- override predicate isSink ( DataFlow:: Node sink ) {
71+ predicate isSink ( DataFlow:: Node sink ) {
7372 exists ( Variable v |
7473 sink .asExpr ( ) = v .getAReference ( )
7574 )
@@ -78,10 +77,11 @@ class TlsConfigCreation extends TaintTracking::Configuration {
7877 /**
7978 * Holds if TLS.Config literal is saved in a structure's field
8079 */
81- override predicate isAdditionalTaintStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
80+ predicate isAdditionalFlowStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
8281 exists ( Write w | w .writesField ( succ , _, pred ) )
8382 }
8483}
84+ module TlsConfigCreationFlow = TaintTracking:: Global< TlsConfigCreationConfig > ;
8585
8686/**
8787 * Holds if `t` is a TLS.Config type or a pointer to it (or ptr to ptr...) or a struct containing it.
@@ -104,14 +104,13 @@ predicate configOrConfigPointer(Type t) {
104104}
105105
106106// v - a variable holding any structure which is or contains the tls.Config
107- from StructLit configStruct , Variable v , TlsConfigCreation cfg , DataFlow:: Node source , DataFlow:: Node sink
107+ from StructLit configStruct , Variable v , DataFlow:: Node source , DataFlow:: Node sink
108108where
109109 // find tls.Config structures with MinVersion not set on the structure initialization
110110 (
111- cfg . hasFlow ( source , sink ) and
111+ TlsConfigCreationFlow :: flow ( source , sink ) and
112112 sink .asExpr ( ) = v .getAReference ( ) and
113- source .asExpr ( ) = configStruct and
114- not cfg .isSecure ( source )
113+ source .asExpr ( ) = configStruct
115114 )
116115
117116 // exclude if tls.Config is used as TLSClientConfig, as default for clients is TLS 1.2
@@ -143,8 +142,8 @@ where
143142 and if configOrConfigPointer ( v .getType ( ) ) then
144143 (
145144 // exclude if there is a later write to MinVersion
146- not exists ( TlsVersionFlowConfig cfg2 , DataFlow:: Node source2 , DataFlow:: Node sink2 |
147- cfg2 . hasFlow ( source2 , sink2 ) and
145+ not exists ( DataFlow:: Node source2 , DataFlow:: Node sink2 |
146+ TlsVersionFlow :: flow ( source2 , sink2 ) and
148147 source2 .asExpr ( ) = v .getAReference ( )
149148 )
150149 ) else
0 commit comments