-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-34155: Dont parse domains containing @ #13079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -1444,6 +1444,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 hidden or 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 hidden or 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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.