File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed
python/ql/src/Security/CWE-327 Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 3
3
"qhelp.dtd">
4
4
<qhelp >
5
5
<overview >
6
- <p > The <code >ssl</code > library defaults to an insecure version of
7
- SSL/TLS when no specific protocol version is specified. This may leave
8
- the connection vulnerable to attack.
6
+ <p >
7
+ In version of Python before 3.4, the <code >ssl</code > library defaults
8
+ to an insecure version of SSL/TLS when no specific protocol version is
9
+ specified. This may leave the connection vulnerable to attack.
9
10
</p >
10
11
11
12
</overview >
16
17
and TLS 1.0 and 1.1 are known to be vulnerable to attacks. Using TLS 1.2 or
17
18
above is strongly recommended. If no explicit
18
19
<code >ssl_version</code > is specified, the default
19
- <code >PROTOCOL_TLS</code > is chosen. This protocol is insecure and
20
- should not be used.
20
+ <code >PROTOCOL_TLS</code > is chosen. This protocol is insecure in that it
21
+ allows TLS 1.0 and TLS 1.1 and so should not be used.
21
22
</p >
22
23
23
24
</recommendation >
46
47
<li ><code >ssl.create_default_context</code > - a convenience function,
47
48
supported in Python 3.4 and later versions.</li >
48
49
</ul >
50
+ <p >
51
+ Note also that, even using these alternatives, it is recommended to
52
+ ensure that a safe protocol is being used. The following code illustrates
53
+ how to use either flags (available since Python 3.2) or the `minimum_version`
54
+ field (favored since Python 3.7) to restrict the protocols accepted when
55
+ creating a connection.
56
+ </p >
57
+
58
+ <sample src =" examples/secure_default_protocol.py" />
49
59
</example >
50
60
51
61
<references >
Original file line number Diff line number Diff line change
1
+ import ssl
2
+
3
+ # Using flags to restrict the protocol
4
+ context = ssl .SSLContext ()
5
+ context .options |= ssl .OP_NO_TLSv1 | ssl .OP_NO_TLSv1_1
6
+
7
+ # Declaring a minimum version to restrict the protocol
8
+ context = ssl .create_default_context ()
9
+ context .minimum_version (ssl .TLSVersion .TLSv1_2 )
You can’t perform that action at this time.
0 commit comments