Improper Certificate Validation Using nntplib
The Python class nntplib.NNTP_SSL by default creates an SSL context that
does not verify the server's certificate if the context parameter is unset or
has a value of None. This means that an attacker can easily impersonate a
legitimate server and fool your application into connecting to it.
If you use nntplib.NNTP_SSL or starttls without a context set, you are
opening your application up to a number of security risks, including:
- Man-in-the-middle attacks
- Session hijacking
- Data theft
Example
import nntplib
with nntplib.NNTP_SSL("news.gmane.io") as n:
n.login("user", "password")
n.group("gmane.comp.python.committers")
Remediation
Set the value of the context keyword argument to
ssl.create_default_context() to ensure the connection is fully verified.
import nntplib
import ssl
with nntplib.NNTP_SSL(
"news.gmane.io",
context=ssl.create_default_context(),
) as n:
n.login("user", "password")
n.group("gmane.comp.python.committers")
See also
- nntplib.NNTP_SSL — NNTP protocol client
- nntplib.NNTP.starttls — NNTP protocol client
- ssl — TLS_SSL wrapper for socket objects
- CWE-295: Improper Certificate Validation
New in version 0.3.14