Skip to content

Commit 8b68912

Browse files
committed
Python: Update help and add example
1 parent 9533c92 commit 8b68912

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

python/ql/src/Security/CWE-327/InsecureDefaultProtocol.qhelp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"qhelp.dtd">
44
<qhelp>
55
<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.
910
</p>
1011

1112
</overview>
@@ -16,8 +17,8 @@
1617
and TLS 1.0 and 1.1 are known to be vulnerable to attacks. Using TLS 1.2 or
1718
above is strongly recommended. If no explicit
1819
<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.
2122
</p>
2223

2324
</recommendation>
@@ -46,6 +47,15 @@
4647
<li><code>ssl.create_default_context</code> - a convenience function,
4748
supported in Python 3.4 and later versions.</li>
4849
</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" />
4959
</example>
5060

5161
<references>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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)

0 commit comments

Comments
 (0)