EmailValidator icon indicating copy to clipboard operation
EmailValidator copied to clipboard

When email top level domain valid but subdomain invalid then check still passes

Open ValCanBuild opened this issue 3 years ago • 7 comments

The DNS validation is passing for an email like the following: [email protected]

There is a misspelling of "environsment-agency" and if you check the DNS records for environsment-agency.gov.uk they show up as empty. But the library seems to only be checking the last part of the domain - gov.uk, not the subdomain as well.

This looks wrong to me. Is it possible to fix?

ValCanBuild avatar Apr 20 '23 08:04 ValCanBuild

Hi @ValCanBuild This is very tricky to fix. There is a thread in #301 about this.

egulias avatar May 22 '23 14:05 egulias

@egulias I don't quite understand how the two issues are connected. I believe this one mainly has to do with the DNSCheckValidation->checkDns function and how it only gets the last part of a host and not the whole thing. Wouldn't it be possible to apply a fix there?

MX records should exist at the dns name equal to whatever is behind the @ in the email address. So only checking the parent domain is a bug. Source: https://www.nslookup.io/learning/dns-record-types/mx/#mx-records-below-the-zone-root

ValCanBuild avatar May 25 '23 07:05 ValCanBuild

@egulias I believe the issue might have been caused by this change: https://github.com/egulias/EmailValidator/pull/355

There's a valid test case for this inside DNSCheckValidationTest but it's marked as skipped for some reason: https://github.com/egulias/EmailValidator/blob/97c28cd611278a5686b7f8b47f4136472bebbe1f/tests/EmailValidator/Validation/DNSCheckValidationTest.php#LL97C33-L97C33

    public function testDNSWarnings()
    {
        $this->markTestSkipped('Need to found a domain with AAAA records and no MX that fails later in the validations');
        $validation = new DNSCheckValidation();
        $expectedWarnings = [NoDNSMXRecord::CODE => new NoDNSMXRecord()];
        $validation->isValid("[email protected]", new EmailLexer());
        $this->assertEquals($expectedWarnings, $validation->getWarnings());
    }

ValCanBuild avatar May 25 '23 08:05 ValCanBuild

@egulias just pinging again on this as I believe it's an open bug in 4.0.1 and above versions of the library.

ValCanBuild avatar Jun 01 '23 08:06 ValCanBuild

Hi @ValCanBuild The reason is written in the skipping function Need to found a domain with AAAA records and no MX that fails later in the validations The thing is I haven't been able to actually test the code that does that type of validation because it looks like it either pass or fails at other points. And also need a domain with AAAA and no MX. I'm happy to review a PR with a proposed fix.

egulias avatar Jun 14 '23 11:06 egulias

@egulias here's a domain with AAAA records or no MX records you can use for the test: dnslookup.io Proof: https://www.nslookup.io/domains/dnslookup.io/dns-records/

ValCanBuild avatar Jun 14 '23 12:06 ValCanBuild