Skip to content

gh-160369: Reject buffered plaintext after IMAP STARTTLS - #160370

Merged
JelleZijlstra merged 6 commits into
python:mainfrom
JelleZijlstra:codex/imap-starttls
Nov 10, 2026
Merged

JelleZijlstra merged 6 commits into
python:mainfrom
JelleZijlstra:codex/imap-starttls

Conversation

@JelleZijlstra

@JelleZijlstra JelleZijlstra commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Reject unexpected plaintext buffered after the STARTTLS response before upgrading the connection, so it cannot be interpreted as TLS-protected server responses. Add regression coverage and a Security NEWS entry.

Closes #160369.

@JelleZijlstra JelleZijlstra added the type-security A security issue label Oct 22, 2026 — with ChatGPT Codex Connector
@JelleZijlstra
JelleZijlstra marked this pull request as ready for review October 22, 2026 22:01
@JelleZijlstra
JelleZijlstra requested a review from a team as a code owner October 22, 2026 22:01
Comment thread Lib/imaplib.py
if typ == 'OK':
if any(self._readbuf):
raise self.abort('unexpected data after STARTTLS response')
self._readbuf = []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to discard all cached state that could have been received before a STARTTLS command, so that includes untagged_responses, too. We should add a test for this case.

@savannahostrowski

Copy link
Copy Markdown
Member

@JelleZijlstra @sethmlarson I was thinking it'd be good to get this into alpha 2 tomorrow if we can. Do you folks think that's doable?

@sethmlarson

sethmlarson commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

@savannahostrowski I think so, @JelleZijlstra I can take over submitting a fix for my comment?

@sethmlarson

Copy link
Copy Markdown
Contributor

@JelleZijlstra Pushed a fix here for you to review: 55f6dda

Comment thread Lib/test/test_imaplib.py Outdated
ssl_context=ssl_context)
client.shutdown()

def test_starttls_discards_untagged_responses(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should be moved into NewIMAPTests, the SSL fixture already makes all commands run as TLS so we don't test what we need to test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the test case in cfc62f0

Comment thread Lib/test/test_imaplib.py Resolved
@hugovk

hugovk commented Nov 10, 2026

Copy link
Copy Markdown
Member

I pushed a commit to skip a test when SSL not available: #160370 (comment). MSan now passes.

@JelleZijlstra
JelleZijlstra merged commit 2f0e294 into python:main Nov 10, 2026
53 checks passed
@JelleZijlstra JelleZijlstra added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 10, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @JelleZijlstra, I could not cleanly backport this to 3.11 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 2f0e294d85c905691e360586ebd1d1f7e7a1f5df 3.11
@miss-islington-app

Copy link
Copy Markdown

Sorry, @JelleZijlstra, I could not cleanly backport this to 3.12 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 2f0e294d85c905691e360586ebd1d1f7e7a1f5df 3.12
@miss-islington-app

Copy link
Copy Markdown

Sorry, @JelleZijlstra, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 2f0e294d85c905691e360586ebd1d1f7e7a1f5df 3.14
@miss-islington-app

Copy link
Copy Markdown

Sorry, @JelleZijlstra, I could not cleanly backport this to 3.13 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 2f0e294d85c905691e360586ebd1d1f7e7a1f5df 3.13
@miss-islington-app

Copy link
Copy Markdown

Sorry, @JelleZijlstra, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 2f0e294d85c905691e360586ebd1d1f7e7a1f5df 3.15
@bedevere-app

bedevere-app Bot commented Nov 10, 2026

Copy link
Copy Markdown

GH-161757 is a backport of this pull request to the 3.11 branch.

@bedevere-app

bedevere-app Bot commented Nov 10, 2026

Copy link
Copy Markdown

GH-161758 is a backport of this pull request to the 3.12 branch.

@bedevere-app

bedevere-app Bot commented Nov 10, 2026

Copy link
Copy Markdown

GH-161759 is a backport of this pull request to the 3.13 branch.

@bedevere-app

bedevere-app Bot commented Nov 10, 2026

Copy link
Copy Markdown

GH-161760 is a backport of this pull request to the 3.14 branch.

@bedevere-app

bedevere-app Bot commented Nov 10, 2026

Copy link
Copy Markdown

GH-161761 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 10, 2026
orsenthil pushed a commit to orsenthil/cpython that referenced this pull request Nov 12, 2026
…n#160370)

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 participants