Problem/Motivation

Emails that pass Drupal's (in this case using egulias/EmailValidator) validation but fail validation in a service being used (for example Amazon's SES) can lead to undeliverable emails or even worse when using something like queue_mail can lead to clogged queues resulting in no email being sent at all.

The issue I'm facing is the validator currently accepts "example@email .com" (with the space) as a valid email. This leads to SES rejecting the email with the message:
Expected response code 250 but got code "554", with message "554 Transaction failed: Domain contains control or whitespace " Due to that email being used in the Reply-To header.

Proposed resolution

Tighten the email validation on the Drupal end, or propose a fix upstream.

CommentFileSizeAuthor
#43 3061074-43.patch2.41 KBlongwave
#41 3061074-41.patch1.11 KBchr.fritsch
#39 3061074-39-8.9.x.patch46.5 KBlongwave
#39 3061074-39-9.1.x.patch5.31 KBlongwave
#39 3061074-39-9.2.x.patch5.27 KBlongwave
#35 3061074-35-8.9.x.patch3.72 KBlongwave
#35 3061074-35-9.1.x.patch3.43 KBlongwave
#35 3061074-35-9.2.x.patch3.39 KBlongwave
#27 3061074-3-testonly.patch635 byteslongwave
#11 3061074-7.patch2.18 KBcilefen
#9 3061074-6.patch2.63 KBcilefen
#9 3061074-5-6-interdiff.txt758 bytescilefen
#8 3061074-5.patch2.63 KBcilefen
#3 3061074-3.patch1.81 KBcilefen
#3 3061074-3-testonly.patch635 bytescilefen
#2 3061074-2.patch1.19 KBcilefen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

acbramley created an issue. See original summary.

cilefen’s picture

Status: Active » Needs review
FileSize
1.19 KB

This seems similar to https://github.com/egulias/EmailValidator/issues/15.

The good news is that you can override or decorate the service while waiting for a solution. You could do the following, for example:

$validator = new EmailValidator();
$multipleValidations = new MultipleValidationWithAnd([
    new RFCValidation(),
    new DNSCheckValidation()
]);
$validator->isValid("example@example .com", $multipleValidations); // FALSE

FWIW here is a patch that changes how Drupal core uses the validator. I haven't tested it in the Drupal context.

cilefen’s picture

cilefen’s picture

The last submitted patch, 2: 3061074-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

The last submitted patch, 3: 3061074-3-testonly.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 3: 3061074-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

cilefen’s picture

Status: Needs work » Needs review
FileSize
2.63 KB
cilefen’s picture

FileSize
758 bytes
2.63 KB

This is probably preferable so as to never have a random fail in UserEditTest.

acbramley’s picture

Yeah the problem is that DNSCheckValidation requires the intl extension.

cilefen’s picture

AFAIK via egulias/EmailValidator issues, the email address you cited in the summary may be technically legal in the email RFC but not actually a routable domain. There are probably other cases of oddities like this.

acbramley’s picture

Thanks so much for jumping on this so fast @cilefen, patch LGTM!

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jungle’s picture

The patch in #11 is still valid. And RED (#3)/GREEN(#11) as expected

+++ b/core/modules/user/tests/src/Functional/UserEditTest.php
@@ -54,7 +54,7 @@ public function testUserEdit() {
-    $edit['mail'] = $this->randomMachineName() . '@new.example.com';
+    $edit['mail'] = $this->randomMachineName() . '@example.org';

Do not understand why this change is necessary. It's out of scope from my understanding. Or am I missed something? Otherwise it's RTBC to me.

Thanks!

jungle’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Bug Smash Initiative

Do not understand why this change is necessary. It's out of scope from my understanding. Or am I missed something? Otherwise it's RTBC to me.

Found in #9

This is probably preferable so as to never have a random fail in UserEditTest.

Then tagging "Bug Smash Initiative" and setting to RTBC.

jungle’s picture

Issue tags: +Random test failure
jungle’s picture

Version: 8.9.x-dev » 9.1.x-dev

Setting the target version to the current dev branch.

larowlan’s picture

There might be an issue here, in so far as existing records that were previously valid, may now be invalid.

I'm going to ask other committers to see if we need to worry about that.

catch’s picture

I think we should do manual testing and decide from there how much of a problem this is, here's some rough steps of things to try:

1. Register an account with an invalid e-mail - foo@example .com
2. Try to register a second account with the 'correct' version of that same e-mail: foo@example.com
3. Apply the patch
4. Log in to the site, go to your user profile, try to save - do you get a validation error?
5. Try to change foo@example .com to foo@example.com and save again.

(also the same steps as above, but missing out step #2)

Will definitely need a change record too.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Back to needs review for now.

longwave’s picture

So I dug into the source package and found some tests that cover this case and more:

https://github.com/egulias/EmailValidator/blob/cfa3d44/tests/EmailValida...

Upstream considers this case as "pass with warnings". Should we expand this issue to fail validation if upstream returns any warnings, rather than add the hardcoded check for spaces? I suspect we should be rejecting cases such as example@invalid.example(examplecomment).com and example@[127.0.0.1] as invalid email addresses as well, even if they are technically valid per the RFC.

larowlan’s picture

Yeah that seems reasonable

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

DieterHolvoet’s picture

Is there any reason not to use both RFCValidation and DNSCheckValidation as in the example in the README of the <a href="https://github.com/egulias/EmailValidator#user-content-available-validations">egulias/EmailValidator</a> repository? This would fix some other issues aswell.

longwave’s picture

@DieterHolvoet I think that would have to be opt-in, as we can't guarantee all Drupal sites have outbound network access to resolve DNS records. There are likely also performance considerations as DNS lookups take time.

longwave’s picture

Between 9.0.x and 9.1.x we upgraded egulias/email-validator and this seems to have resolved this issue.

Reuploading the test-only patch from #3.

If 9.0.x fails but 9.1.x passes I think we can just close this as won't fix.

Status: Needs review » Needs work

The last submitted patch, 27: 3061074-3-testonly.patch, failed testing. View results

longwave’s picture

Status: Needs work » Needs review
acbramley’s picture

Issue tags: -Needs manual testing

Nice catch @longwave!! I think we can safely remove Needs manual testing as you found this fix via manual testing :)

longwave’s picture

Title: egulias/EmailValidator allows addresses with a space in the domain part » egulias/EmailValidator prior to 2.1.22 allows addresses with a space in the domain part
Status: Needs review » Active
Issue tags: -Novice, -Needs change record

Upstream this looks to be fixed by https://github.com/egulias/EmailValidator/commit/fda08d3d1b37d20e0a168e0... in 2.1.22.

However even in 9.2.x we only have a minimum version of egulias/email-validator:^2.0 and we have no specific test for this case or min-max dependency testing that would cover this.

So what do we do now? Should we bump the minimum version of egulias/email-validator? Should we add a specific test for this?

longwave’s picture

Bumping this one, as I've run into a production bug around this issue.

I have a site on 8.9.x using Drupal Commerce. A customer accidentally put a space in the domain part of their email address at checkout. I have a custom third party integration at the end of the checkout process that requires a valid email address. This integration failed due to a validation error, and so the order was stuck in Placed state and never completed.

This site is using drupal/core-recommended so egulias/email-validator is pinned to 2.1.17 and I can't just bump the version to fix the root cause of the bug.

Are we allowed to bump minor versions of dependencies in bug fix releases of core to solve issues like this?

longwave’s picture

https://www.drupal.org/about/core/policies/core-dependencies-policies/co... says

Patch-level updates may be done in patch releases to resolve bugs or security issues, but we do not provide patch updates in every patch release since there is a risk of disruption due to upstream regressions.

In this case I think the risk of regression is small and the bug is worth fixing, therefore we should bump the minimum version of egulias/email-validator in all supported branches.

cilefen’s picture

2.1.17 to 2.1.22 is a patch level change and can be done in any Drupal release to fix bugs.

longwave’s picture

The last submitted patch, 35: 3061074-35-9.2.x.patch, failed testing. View results

The last submitted patch, 35: 3061074-35-9.1.x.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 35: 3061074-35-8.9.x.patch, failed testing. View results

longwave’s picture

Forgot to run composer update --lock

8.9.x patch is much bigger because all the "support" sections are added to the lock file.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

chr.fritsch’s picture

We should get this done, not only because of the spacing issue also versions prior to 2.1.16 throw an error "Trying to access array offset on value of type null" on PHP 7.4

See https://github.com/egulias/EmailValidator/commit/5065fafc8c29d229ff207f2...

Status: Needs review » Needs work

The last submitted patch, 41: 3061074-41.patch, failed testing. View results

longwave’s picture

Status: Needs work » Needs review
FileSize
2.41 KB

composer.lock also needs updating.

init90’s picture

Status: Needs review » Reviewed & tested by the community

LGTM

alexpott’s picture

Priority: Normal » Critical

Bumping this to critical since PHP 7.3 is about to be unsupported and our minimum version constraints will not be compatible with the minimum supported version of PHP - which seems really odd.

In an ideal world composer would fix this for us and somehow know which version of egulias/EmailValidator to choose but there's no way to update old releases and say that it's not compatible with a PHP version that was not around when it was released.

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs manual testing

I think we still need the manual testing from #3061074-20: egulias/EmailValidator prior to 2.1.22 allows addresses with a space in the domain part for what behaviour we get with existing data, and whether it's allowed duplicate e-mail addresses to be used. The tag was removed, but that seems to have been unrelated to the upgrade path.

longwave’s picture

Note that 9.1.x shipped with 2.1.22 and 9.2.x/9.3.x/9.4.x already ship with 2.1.25, and these versions will be used by core-recommended. This issue is now just changing the minimum version that is present in composer.json to prevent older versions from being used, and adding a test for the previously broken behaviour.

See also #3238763: Upgrade egulias/email-validator to v3 as I think 2.1.25 is likely the last release of the 2.x series.

  • catch committed b9a61af on 9.4.x
    Issue #3061074 by longwave, cilefen, chr.fritsch, acbramley, jungle,...

  • catch committed f515436 on 9.3.x
    Issue #3061074 by longwave, cilefen, chr.fritsch, acbramley, jungle,...
catch’s picture

Status: Needs review » Fixed
Issue tags: -Needs manual testing

OK that's fair enough, if we've already updated it doesn't make sense to hold up changing the minimum version to the one we've already updated to.

Committed/pushed to 9.4.x and cherry-picked to 9.3.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.