stampery / mongoaudit

🔥 A powerful MongoDB auditing and pentesting tool 🔥
https://mongoaud.it
MIT License
1.32k stars 135 forks source link

Updated email regex #20

Closed Ekultek closed 7 years ago

Ekultek commented 7 years ago

Updated the email regex to be a little more accurate

Example:

>>> emails = ["almira_eckl@mail.com", "por.bop@msn.com", "trinit_eckley@myspace.com", "fifranc@freewebmail.com"]
>>> def validate_email(email):
        import re
        valid = re.compile(r"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$")
        if valid.match(email):
        print "yes"
    else: print "No"

>>> for item in emails:
    validate_email(item)

yes
yes
yes
yes
>>> 
kronolynx commented 7 years ago

The proposed regex would fail for ICANN-era TLDs

https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#ICANN-era_generic_top-level_domains

Ekultek commented 7 years ago

Did some testing:

>>> def validate_email_1(email):
    import re
    valid = re.compile(r"^[^@]+@[^@]+\.[^@]+$")
    if valid.match(email):
        print "Validation method 1 matched"
    else:
        print "Validation method 1 failed"

>>> def validate_email_2(email):
    import re
    valid = re.compile(r"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$")
    if valid.match(email):
        print "Validation method 2 matched"
    else:
        print "Validation method 2 failed"

>>> emails = ["almira_eckl@mail.com", "por.bop@msn.com", "trinit_eckley@myspace.com", "fifranc@freewebmail.com", "test@test.academy", "test@test.accountant", "test@test.accountants"]
>>> for item in emails:
    validate_email_1(item)
    validate_email_2(item)

Validation method 1 matched
Validation method 2 matched
Validation method 1 matched
Validation method 2 matched
Validation method 1 matched
Validation method 2 matched
Validation method 1 matched
Validation method 2 matched
Validation method 1 matched
Validation method 2 failed
Validation method 1 matched
Validation method 2 failed
Validation method 1 matched
Validation method 2 failed

On that note, closing the pull request down

aesedepece commented 7 years ago

Hi @Ekultek First of all, thanks a lot for your PR! It makes us specially happy to see people contributing! Please feel free to update this PR or open another with a regex that take into account the aforementioned TLDs.

Ekultek commented 7 years ago

@aesedepece Will do I'll figure one out, thanks. I'll reopen it when I get it fixed