Skip to content

Commit abb5816

Browse files
committed
gh-91826: Document that smtplib/poplib/ftplib TLS defaults do not verify certs
Mirror the imaplib note from gh-72507 / PR #152778 so users of SMTP, POP and FTP TLS APIs know the default context encrypts but does not authenticate. Also list the four modules in Doc/library/security_warnings.rst.
1 parent f5f5059 commit abb5816

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

Doc/library/ftplib.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,13 @@ FTP_TLS objects
480480
Please read :ref:`ssl-security` for best practices.
481481
:type context: :class:`ssl.SSLContext`
482482

483+
.. note::
484+
485+
With the default *context*, the connection is encrypted but the
486+
server certificate and hostname are not verified.
487+
To verify them, pass a context created by
488+
:func:`ssl.create_default_context`.
489+
483490
:param timeout:
484491
A timeout in seconds for blocking operations like :meth:`~FTP.connect`
485492
(default: the global default timeout setting).

Doc/library/poplib.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ The :mod:`!poplib` module provides two classes:
6060
single (potentially long-lived) structure. Please read :ref:`ssl-security`
6161
for best practices.
6262

63+
.. note::
64+
65+
With the default *context*, the connection is encrypted but the
66+
server certificate and hostname are not verified.
67+
To verify them, pass a context created by
68+
:func:`ssl.create_default_context`.
69+
6370
.. audit-event:: poplib.connect self,host,port poplib.POP3_SSL
6471

6572
.. audit-event:: poplib.putline self,line poplib.POP3_SSL
@@ -235,6 +242,13 @@ A :class:`POP3` instance has the following methods:
235242
a single (potentially long-lived) structure. Please read :ref:`ssl-security`
236243
for best practices.
237244

245+
.. note::
246+
247+
With the default *context*, the connection is encrypted but the
248+
server certificate and hostname are not verified.
249+
To verify them, pass a context created by
250+
:func:`ssl.create_default_context`.
251+
238252
This method supports hostname checking via
239253
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
240254
:const:`ssl.HAS_SNI`).

Doc/library/security_warnings.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,28 @@ The following modules have specific security considerations:
99

1010
* :mod:`base64`: :ref:`base64 security considerations <base64-security>` in
1111
:rfc:`4648`
12+
* :mod:`ftplib`: default TLS context does not verify server certificates;
13+
pass a context from :func:`ssl.create_default_context` to verify them
1214
* :mod:`hashlib`: :ref:`all constructors take a "usedforsecurity" keyword-only
1315
argument disabling known insecure and blocked algorithms
1416
<hashlib-usedforsecurity>`
1517
* :mod:`http.server` is not suitable for production use, only implementing
1618
basic security checks. See the :ref:`security considerations <http.server-security>`.
19+
* :mod:`imaplib`: default TLS context does not verify server certificates;
20+
pass a context from :func:`ssl.create_default_context` to verify them
1721
* :mod:`logging`: :ref:`Logging configuration uses eval()
1822
<logging-eval-security>`
1923
* :mod:`multiprocessing`: :ref:`Connection.recv() uses pickle
2024
<multiprocessing-recv-pickle-security>`
2125
* :mod:`pickle`: :ref:`Restricting globals in pickle <pickle-restrict>`
26+
* :mod:`poplib`: default TLS context does not verify server certificates;
27+
pass a context from :func:`ssl.create_default_context` to verify them
2228
* :mod:`random` shouldn't be used for security purposes, use :mod:`secrets`
2329
instead
2430
* :mod:`shelve`: :ref:`shelve is based on pickle and thus unsuitable for
2531
dealing with untrusted sources <shelve-security>`
32+
* :mod:`smtplib`: default TLS context does not verify server certificates;
33+
pass a context from :func:`ssl.create_default_context` to verify them
2634
* :mod:`ssl`: :ref:`SSL/TLS security considerations <ssl-security>`
2735
* :mod:`subprocess`: :ref:`Subprocess security considerations
2836
<subprocess-security>`

Doc/library/smtplib.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
9898
aspects of the secure connection. Please read :ref:`ssl-security` for
9999
best practices.
100100

101+
.. note::
102+
103+
With the default *context*, the connection is encrypted but the
104+
server certificate and hostname are not verified.
105+
To verify them, pass a context created by
106+
:func:`ssl.create_default_context`.
107+
101108
.. attribute:: SMTP_SSL.default_port
102109

103110
The default port used for SMTP-over-SSL connections (465).
@@ -422,6 +429,13 @@ An :class:`SMTP` instance has the following methods:
422429
an alternative to using a keyfile and a certfile and if specified both
423430
*keyfile* and *certfile* should be ``None``.
424431

432+
.. note::
433+
434+
With the default *context*, the connection is encrypted but the
435+
server certificate and hostname are not verified.
436+
To verify them, pass a context created by
437+
:func:`ssl.create_default_context`.
438+
425439
If there has been no previous ``EHLO`` or ``HELO`` command this session,
426440
this method tries ESMTP ``EHLO`` first.
427441

0 commit comments

Comments
 (0)