@@ -7,8 +7,15 @@ class SSLContextCreation extends ContextCreation {
7
7
8
8
SSLContextCreation ( ) { this = API:: moduleImport ( "ssl" ) .getMember ( "SSLContext" ) .getACall ( ) }
9
9
10
- override DataFlow:: CfgNode getProtocol ( ) {
11
- result .getNode ( ) in [ node .getArg ( 0 ) , node .getArgByName ( "protocol" ) ]
10
+ override string getProtocol ( ) {
11
+ exists ( ControlFlowNode protocolArg , Ssl ssl |
12
+ protocolArg in [ node .getArg ( 0 ) , node .getArgByName ( "protocol" ) ]
13
+ |
14
+ protocolArg = [ ssl .specific_version ( result ) , ssl .unspecific_version ( result ) ] .asCfgNode ( )
15
+ )
16
+ or
17
+ not exists ( node .getAnArg ( ) ) and
18
+ result = "TLS"
12
19
}
13
20
}
14
21
@@ -19,7 +26,7 @@ class SSLDefaultContextCreation extends ContextCreation {
19
26
20
27
// Allowed insecure versions are "TLSv1" and "TLSv1_1"
21
28
// see https://docs.python.org/3/library/ssl.html#context-creation
22
- override DataFlow :: CfgNode getProtocol ( ) { none ( ) }
29
+ override string getProtocol ( ) { result = "TLS" }
23
30
}
24
31
25
32
/** Gets a reference to an `ssl.Context` instance. */
@@ -141,17 +148,10 @@ class UnspecificSSLContextCreation extends SSLContextCreation, UnspecificContext
141
148
UnspecificSSLContextCreation ( ) { library = "ssl" }
142
149
143
150
override ProtocolVersion getUnrestriction ( ) {
144
- // Case: A protocol argument is present.
145
151
result = UnspecificContextCreation .super .getUnrestriction ( ) and
146
152
// These are turned off by default
147
153
// see https://docs.python.org/3/library/ssl.html#ssl-contexts
148
154
not result in [ "SSLv2" , "SSLv3" ]
149
- or
150
- // Case: No protocol arguemnt is present.
151
- not exists ( this .getProtocol ( ) ) and
152
- // The default argument is TLS and the SSL versions are turned off by default since Python 3.6
153
- // see https://docs.python.org/3.6/library/ssl.html#ssl.SSLContext
154
- result in [ "TLSv1" , "TLSv1_1" , "TLSv1_2" , "TLSv1_3" ]
155
155
}
156
156
}
157
157
@@ -185,8 +185,9 @@ class Ssl extends TlsLibrary {
185
185
186
186
override DataFlow:: CfgNode insecure_connection_creation ( ProtocolVersion version ) {
187
187
result = API:: moduleImport ( "ssl" ) .getMember ( "wrap_socket" ) .getACall ( ) and
188
- insecure_version ( version ) .asCfgNode ( ) =
189
- result .asCfgNode ( ) .( CallNode ) .getArgByName ( "ssl_version" )
188
+ specific_version ( version ) .asCfgNode ( ) =
189
+ result .asCfgNode ( ) .( CallNode ) .getArgByName ( "ssl_version" ) and
190
+ version .isInsecure ( )
190
191
}
191
192
192
193
override ConnectionCreation connection_creation ( ) { result instanceof WrapSocketCall }
0 commit comments