You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I think what's happening is that the $ is misplaced for domains. The part of the regex that deals with actual domains (rather than IP addresses) is r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+' r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?$)'
The problem is that this permits arbitrary trailing characters, such as '>' after a valid domain, because it matches just the domain, not the invalid trailing characters.
Later, the code tests whether there was a match, not whether the input was matched perfectly.
It appears that the intent was that the second part of the pattern would ensure termination, because it has a $. But the $ is part of a regex group that is not necessary to match 'example.org', so that group is ignored and 'example.org>' matches the regex just fine. Moving the $ after the second part of the pattern does solve this:
>>> re.match(r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+' r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)$', 'example.org>', re.IGNORECASE).group(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
>>> re.match(r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+' r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)$', 'example.org', re.IGNORECASE).group(0)
'example.org'
>>>
Checking whether match.group(0) == domain_part would also solve this, and might be more robust.
Activity
tempico commentedon Sep 11, 2017
bypass PoC with flask
abentley commentedon Feb 23, 2018
So I think what's happening is that the $ is misplaced for domains. The part of the regex that deals with actual domains (rather than IP addresses) is
r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+' r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?$)'The problem is that this permits arbitrary trailing characters, such as '>' after a valid domain, because it matches just the domain, not the invalid trailing characters.
Later, the code tests whether there was a match, not whether the input was matched perfectly.
It appears that the intent was that the second part of the pattern would ensure termination, because it has a $. But the $ is part of a regex group that is not necessary to match 'example.org', so that group is ignored and 'example.org>' matches the regex just fine. Moving the $ after the second part of the pattern does solve this:
Checking whether match.group(0) == domain_part would also solve this, and might be more robust.
maint: improves `email` module
maint: improves `email` module
maint: improves `email` module