-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Before: >>> email.message_from_string('From: [email protected]@important.com', policy=email.policy.default)['from'].addresses (Address(display_name='', username='a', domain='malicious.org'),) >>> parseaddr('[email protected]@important.com') ('', '[email protected]') After: >>> email.message_from_string('From: [email protected]@important.com', policy=email.policy.default)['from'].addresses (Address(display_name='', username='', domain=''),) >>> parseaddr('[email protected]@important.com') ('', 'a@') https://bugs.python.org/issue34155
- Loading branch information
1 parent
719a062
commit 8cb65d1
Showing
5 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,7 +379,12 @@ def getaddrspec(self): | |
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 @@ def getdomain(self): | |
elif self.field[self.pos] == '.': | ||
self.pos += 1 | ||
sdlist.append('.') | ||
elif self.field[self.pos] == '@': | ||
# bpo-34155: Don't parse domains with two `@` like | ||
# `[email protected]@important.com`. | ||
return EMPTYSTRING | ||
elif self.field[self.pos] in self.atomends: | ||
break | ||
else: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1448,6 +1448,16 @@ def test_get_addr_spec_dot_atom(self): | |
self.assertEqual(addr_spec.domain, 'example.com') | ||
self.assertEqual(addr_spec.addr_spec, '[email protected]') | ||
|
||
def test_get_addr_spec_multiple_domains(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_addr_spec('[email protected]@example.com') | ||
|
||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_addr_spec('star@[email protected]') | ||
|
||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_addr_spec('[email protected]@example.com') | ||
|
||
# get_obs_route | ||
|
||
def test_get_obs_route_simple(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3041,6 +3041,20 @@ def test_parseaddr_empty(self): | |
self.assertEqual(utils.parseaddr('<>'), ('', '')) | ||
self.assertEqual(utils.formataddr(utils.parseaddr('<>')), '') | ||
|
||
def test_parseaddr_multiple_domains(self): | ||
self.assertEqual( | ||
utils.parseaddr('a@b@c'), | ||
('', '') | ||
) | ||
self.assertEqual( | ||
utils.parseaddr('[email protected]@c'), | ||
('', '') | ||
) | ||
self.assertEqual( | ||
utils.parseaddr('[email protected]@c'), | ||
('', '') | ||
) | ||
|
||
def test_noquote_dump(self): | ||
self.assertEqual( | ||
utils.formataddr(('A Silly Person', '[email protected]')), | ||
|
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Security/2019-05-04-13-33-37.bpo-34155.MJll68.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix parsing of invalid email addresses with more than one ``@`` (e.g. a@[email protected].) to not return the part before 2nd ``@`` as valid email address. Patch by maxking & jpic. |