GHSA-vxj7-4xrp-5vr4: Medium severity pip/aiosmtplib vulnerability

Published Aug 27, 2026
·
Updated

Impact

When a connection is upgraded with STARTTLS, aiosmtplib reads the server's 220 go-ahead reply and immediately performs the TLS handshake without discarding any data still sitting in the receive buffer. Bytes the protocol read off the plaintext socket before the handshake survive across the plaintext→TLS boundary (the asyncio transport is swapped in place, so the protocol object and its buffer are reused), and are then parsed as though they had arrived inside the TLS session.

Who is affected: Any caller that uses STARTTLS by passing starttls=True or starttls=None when the server advertises STARTTLS, and whose traffic can be intercepted by an active network attacker on the plaintext leg of the connection.

A man in the middle can send, in a single segment immediately after the client's STARTTLS command, the 220 reply followed by attacker-chosen response lines (e.g. 220 Go ahead\r\n250-mx.evil\r\n250 AUTH LOGIN\r\n). aiosmtplib consumes only the 220, leaves the injected lines buffered, completes the handshake, and then parses the attacker's pre-staged plaintext as the first post-TLS server response. This also desynchronizes every subsequent command/response pair inside the "encrypted" session.

Not affected: Connections using implicit/direct TLS (usetls=True) have no plaintext phase and are not vulnerable. The attack requires an active man in the middle via network compromise; a passive eavesdropper cannot exploit it.

Patches

A fix is available in aiosmtplib 5.1.2. All earlier versions that support STARTTLS are affected; upgrade to 5.1.2 or later.

The fix treats any data buffered after the 220 STARTTLS reply and before the handshake as a protocol violation, per RFC 3207 §4.2 ("the client MUST discard any knowledge obtained from the server … which was not obtained from the TLS negotiation itself").

Workarounds

If you cannot upgrade immediately:

- Use implicit TLS instead of STARTTLS. Connect with usetls=True. This removes the plaintext phase entirely. - If STARTTLS is unavoidable, restrict connections to servers reached over a trusted network path.

Affected Software

1 affected componentFixes available
pip/aiosmtplib<=5.1.1
5.1.2

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/aiosmtplib to a version that resolves this vulnerability.

    Fixed in 5.1.2
  2. Upgrade

    Upgrade aiosmtplib to a version that resolves this vulnerability.

    Fixed in 5.1.2
  3. Configuration

    Connect using implicit/direct TLS by setting use_tls=True instead of using STARTTLS (STARTTLS is described as vulnerable for affected callers using start_tls=True/start_tls=None).

    aiosmtplib client (SMTP) use_tls = True
  4. Configuration

    If possible, avoid STARTTLS by not using start_tls=True or start_tls=None when the server advertises STARTTLS; implicit/direct TLS with use_tls=True is noted as not vulnerable.

    aiosmtplib client (SMTP) start_tls = False
  5. Compensating control

    If STARTTLS is unavoidable, restrict connections to servers reached over a trusted network path (mitigating the requirement for an active man-in-the-middle on the plaintext leg).

Event History

Aug 27, 2026
Advisory Published
via GitHub·11:32 PM
Data Sourced
via GitHub·11:32 PM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

Which deployments are exposed?

Callers using STARTTLS are affected: those that set start_tls=True, or set start_tls=None when the SMTP server advertises STARTTLS. Exploitation additionally requires an active network attacker able to intercept traffic during the plaintext portion of the connection.

2

Does an attacker need credentials or user interaction?

No. The supplied vector lists no privileges and no user interaction requirements; the attacker injects a forged STARTTLS response and additional SMTP response lines on the plaintext connection.

3

What can exploitation cause?

Injected plaintext response lines can be interpreted as the first server response after TLS is established. This desynchronizes subsequent SMTP command and response pairs, and the vulnerability is rated as having high integrity impact.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203