Hi Everyone,
I searched through the mailing list history, but I did not see this
discussion. This is one of my pet peeves because I still encounter
businesses, hotel chains, airlines, and train operators that do not
accept my email address like "
noloade...@gmail.com". For
businesses I really don't like, I might generate a throw-away using a
UUID-like local-part:
noloader+G2ZYXG6...@gmail.com. I
usually encounter some nondescript errors after the data-api layer
fails asynchronously.
Email address validation has been a contentious painpoint between the
IETF and the WHATWG for years.[2,3] Email addresses are controlled by
the IETF's EmailCore Working Group, but the WHATWG does not want to
stay in its lane.
Let's get to it... From src/test/resources/esapi/validation.properties
in Develop [0]. Notice test/ and not configuration/ because
Validator.Gmail only shows up in Test:
Validator.Email=^[A-Za-z0-9._%'-]+@[A-Za-z0-9.-]+\\.[a-zA-Z]{2,62}$
Validator.Gmail=^[A-Za-z0-9._%'-+]+@[A-Za-z0-9.-]+\\.[a-zA-Z]{2,62}$
There are several complaints:
1. Validator.Email is not accurate today or yesterday
2. Validator.Gmail is better but still not accurate and misleading
3. Senders should not try to interpret an email address
4. WHATWG and <input=email> is wrong
The message closes with a fifth section:
5. Recommendations
1. Validator.Email is not accurate today or yesterday
=====================================================
An email address is defined in RFC 5322. It was published by the
IETF's EmailCore Working Group. An email address cannot be validated
using a regex. The RFCs state an email address consists of a
local-part and a domain (lots of hand-waving):
local-part@domain
Here are some valid email addresses from the RFC. The "lots of
hand-waving" comes from the fact it is much worse than this:
jo...@example.com
john...@example.com
"John Doe"@
example.com (local-part is case sensitive)
"john doe"@
example.com (local-part is case sensitive)
john.doe...@example.com (Email Filtering, Subaddress Extension)
john.doe...@example.com (Email Filtering, Subaddress Extension)
john.doe...@example.com (Email Filtering, Subaddress Extension)
john@localhost (not routable on public internet)
john.doe@localhost (not routable on public internet)
john@[172.16.1.2] (requires brackets, not routable on public internet)
john.doe@[172.16.1.2] (requires brackets, not routable on public internet)
Most validation performed in the Web context fails for common cases
nowadays, like RFC 5233, Sieve Email Filtering: Subaddress Extension,
a/k/a "Subaddresses" or "Plus addresses".
About the best a sender can do for validation is ensure there is a
local-part to the left of the '@' sign, and the domain on the right of
the '@' sign has a DNS record.
For completeness, I'm not arguing for allowed but uncommon cases, like
case-sensitive local parts, quoted local-part with whitespace, or IP
addresses. I just wanted to show what could be allowed if ESAPI
wanted to provide richer validation, and why it's a bad idea to
interpret the validity of an email address locally.
2. Validator.Gmail is better but still not accurate and misleading
==================================================================
Validator.Gmail improves upon 1. Validator.Email is not accurate today
by allowing Subaddresses or "Plus addresses" from RFC 5233.
However, RFC 5233 is supported by most major email providers, and not
just Gmail. Email provider support includes Gmail, Fastmail, Yahoo,
MS 365 Office and Outlook.
3. Senders should not try to interpret an email address
=======================================================
According to the EmailCore Working Group, senders should not attempt
to interpret an email address. The email should be sent, and if the
email is invalid, then the sender will receive a Non Delivery Report
(NDR).
About the best a sender can do for validation is ensure there is a
local-part to the left of the '@' sign, and the domain on the right of
the '@' sign has a DNS record.
4. WHATWG and <input=email> validation is wrong
===============================================
The WHATWG recommendation is simply wrong.[1] It does not handle
subaddresses ("plus" addresses), like "
john.d...@example.com". It
also rejects a lot of other valid email addresses. And it violates
(3) Senders should not try to interpret an email address.
<SNIP>
A valid email address is a string that matches the email production of
the following ABNF, the character set for which is Unicode. This ABNF
implements the extensions described in RFC 1123. [ABNF] [RFC5322]
[RFC1034] [RFC1123]
email = 1*( atext / "." ) "@" label *( "." label )
label = let-dig [ [ ldh-str ] let-dig ] ; limited to a length
of 63 characters by RFC 1034 section 3.5
atext = < as defined in RFC 5322 section 3.2.3 >
let-dig = < as defined in RFC 1034 section 3.5 >
ldh-str = < as defined in RFC 1034 section 3.5 >
</SNIP>
Note that at the end of the section states:
<SNIP>
This requirement is a willful violation of RFC 5322, which defines a
syntax for email addresses that is simultaneously too strict (before
the "@" character), too vague (after the "@" character), and too lax
(allowing comments, whitespace characters, and quoted strings in
manners unfamiliar to most users) to be of practical use here.
</SNIP>
5. Recommendations
==================
1. In configuration.properties, add Validator.SimpleEmail using the
same regex as Validator.Email. Deprecate Validator.Email since it is
not descriptive. Do not recommend use of Validator.Email or
Validator.SimpleEmail.
1. In configuration.properties, add Validator.EmailWithSubaddress
using the same regex as Validator.Gmail. Deprecate Validator.Gmail in
Test since it is not descriptive. Do not recommend use of
Validator.EmailWithSubaddress.
3. Recommend that senders should not try to interpret the local-part
of an email address. Only the receiving MTA can do it reliably and
accurately.
4. Recommend the validation for an email address is to ensure
local-part is not empty, there is an '@' sign, and there is a domain
part that could include "localhost" or other label that does not
resolve in DNS. Then, send the email. If the sender receives a Non
Delivery Report (NDR), then the email address is bad.
Jeff
[0]
https://github.com/ESAPI/esapi-java-legacy/blob/develop/src/test/resources/esapi/validation.properties
[1]
https://html.spec.whatwg.org/#email-state-(type=email)
[2]
https://github.com/ietf-wg-emailcore/emailcore/issues/51
[3]
https://github.com/ietf-wg-emailcore/emailcore/issues/137