mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
bpo-34155: Dont parse domains containing @ (GH-13079)
Before:
>>> email.message_from_string('From: a@malicious.org@important.com', policy=email.policy.default)['from'].addresses
(Address(display_name='', username='a', domain='malicious.org'),)
>>> parseaddr('a@malicious.org@important.com')
('', 'a@malicious.org')
After:
>>> email.message_from_string('From: a@malicious.org@important.com', policy=email.policy.default)['from'].addresses
(Address(display_name='', username='', domain=''),)
>>> parseaddr('a@malicious.org@important.com')
('', 'a@')
https://bugs.python.org/issue34155
(cherry picked from commit 8cb65d1381
)
Co-authored-by: jpic <jpic@users.noreply.github.com>
This commit is contained in:
parent
162d45c531
commit
217077440a
5 changed files with 37 additions and 1 deletions
|
@ -1566,6 +1566,8 @@ def get_domain(value):
|
|||
token, value = get_dot_atom(value)
|
||||
except errors.HeaderParseError:
|
||||
token, value = get_atom(value)
|
||||
if value and value[0] == '@':
|
||||
raise errors.HeaderParseError('Invalid Domain')
|
||||
if leader is not None:
|
||||
token[:0] = [leader]
|
||||
domain.append(token)
|
||||
|
|
|
@ -379,7 +379,12 @@ class AddrlistClass:
|
|||
aslist.append('@')
|
||||
self.pos += 1
|
||||
self.gotonext()
|
||||
return EMPTYSTRING.join(aslist) + self.getdomain()
|
||||
domain = self.getdomain()
|
||||
if not domain:
|
||||
# Invalid domain, return an empty address instead of returning a
|
||||
# local part to denote failed parsing.
|
||||
return EMPTYSTRING
|
||||
return EMPTYSTRING.join(aslist) + domain
|
||||
|
||||
def getdomain(self):
|
||||
"""Get the complete domain name from an address."""
|
||||
|
@ -394,6 +399,10 @@ class AddrlistClass:
|
|||
elif self.field[self.pos] == '.':
|
||||
self.pos += 1
|
||||
sdlist.append('.')
|
||||
elif self.field[self.pos] == '@':
|
||||
# bpo-34155: Don't parse domains with two `@` like
|
||||
# `a@malicious.org@important.com`.
|
||||
return EMPTYSTRING
|
||||
elif self.field[self.pos] in self.atomends:
|
||||
break
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue