Skip to content

Commit 481ca55

Browse files
committed
Implement challenge count limit
Broken/buggy server might 'trap' us in AUTH. We raise an exception and let the user handle things.
1 parent dca899d commit 481ca55

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Lib/smtplib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
CRLF = "\r\n"
6565
bCRLF = b"\r\n"
6666
_MAXLINE = 8192 # more than 8 times larger than RFC 821, 4.5.3
67+
_MAXCHALLENGE = 5 # Maximum number of AUTH challenges sent
6768

6869
OLDSTYLE_AUTH = re.compile(r"auth=(.*)", re.I)
6970

@@ -645,6 +646,12 @@ def auth(self, mechanism, authobject, *, initial_response_ok=True):
645646
response = encode_base64(
646647
authobject(challenge).encode('ascii'), eol='')
647648
(code, resp) = self.docmd(response)
649+
# If server keeps sending challenges, something is wrong.
650+
if self._auth_challenge_count > _MAXCHALLENGE:
651+
raise SMTPException(
652+
"Server AUTH mechanism infinite loop. Last response: "
653+
+ repr((code, resp))
654+
)
648655
if code in (235, 503):
649656
return (code, resp)
650657
raise SMTPAuthenticationError(code, resp)

0 commit comments

Comments
 (0)