GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-34155: Dont parse domains containing @ by jpic · Pull Request #13079 · python/cpython

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.

Sign up for GitHub

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
miss-islington merged 1 commit into python:master from jpic:bpo-34155
Jul 17, 2019

Uh oh!

There was an error while loading. Please reload this page.

Merged

bpo-34155: Dont parse domains containing @ #13079

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
3263dac
bpo-34155: Fail parse of multiple email domains
jpic Jul 3, 2019
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

2 changes: 2 additions & 0 deletions 2 Lib/email/_header_value_parser.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,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')
Comment thread
warsaw marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

if leader is not None:
token[:0] = [leader]
domain.append(token)
Expand Down
11 changes: 10 additions & 1 deletion 11 Lib/email/_parseaddr.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions 10 Lib/test/test_email/test__header_value_parser.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions 14 Lib/test/test_email/test_email.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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]')),
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Security/2019-05-04-13-33-37.bpo-34155.MJll68.rst
Show comments
View file
Open in desktop
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.