-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathInsecureDefaultProtocol.ql
More file actions
46 lines (43 loc) · 1.87 KB
/
InsecureDefaultProtocol.ql
File metadata and controls
46 lines (43 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @name Default version of SSL/TLS may be insecure
* @description Leaving the SSL/TLS version unspecified may result in an insecure
* default protocol being used.
* @id py/insecure-default-protocol
* @kind problem
* @problem.severity warning
* @precision high
* @tags security
* external/cwe/cwe-327
*/
// This query is based on the premise that default constructors are always a security concern.
// This has become untrue since Python 3.4 where flags such as `OP_NO_TLSv1_1` were introduced
// on the `options` field to modify contexts created with default values. These flags are now,
// since OpenSSL1.1.0, themselves deprecated in favor of the `minimum_version` field (and its
// counterpart `maximum_version`).
//
// Detecting that a connection is created with a context that has not been suitably modified is
// handled by the data-flow query py/insecure-protocol, while the present query is restricted
// to alerting on default constructors when the Python version is earlier than 3.4.
import python
import semmle.python.ApiGraphs
CallNode unsafe_call(string method_name) {
result = API::moduleImport("ssl").getMember("wrap_socket").getACall().asCfgNode() and
not exists(result.getArgByName("ssl_version")) and
method_name = "deprecated method ssl.wrap_socket"
or
result = API::moduleImport("ssl").getMember("SSLContext").getACall().asCfgNode() and
not exists(result.getArgByName("protocol")) and
not exists(result.getArg(0)) and
method_name = "ssl.SSLContext" and
// in version 3.4, flags were introduced to modify contexts created with default values
(
major_version() = 2
or
major_version() = 3 and minor_version() < 4
)
}
from CallNode call, string method_name
where call = unsafe_call(method_name)
select call,
"Call to " + method_name +
" does not specify a protocol, which may result in an insecure default being used."