Mthe beseti
Mthe beseti

Reputation: 619

Magento hostname validation errors

When i tried to register with an email on magento store that I am developing I came across with errors that i havent seen before that says:

"Email" is not a valid hostname

does not appear to be a valid local network name

appears to be a DNS hostname but cannot match TLD against known list magento

When I did my research I foundout that these errors comes are caused by the Zend hostname validation.

Is it possible to resolve these or there's no solution at all

Upvotes: 4

Views: 7479

Answers (2)

DependencyHell
DependencyHell

Reputation: 1071

I encountered same error :

"Email" is not a valid hostname.
'example.example' appears to be a DNS hostname but cannot match TLD against known list
'example.example' appears to be a local network name but local network names are not allowed

From Magento 1, it appears that Zend is using a hardcoded list of Tlds :

     /**
     * Array of valid top-level-domains
     *
     * @see ftp://data.iana.org/TLD/tlds-alpha-by-domain.txt  List of all TLDs by domain
     * @see http://www.iana.org/domains/root/db/ Official list of supported TLDs
     * @var array
     */
    protected $_validTlds = array(
        'ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa',
        [...]
        'ye', 'yt', 'yu', 'za', 'zm', 'zw'
    );

So, there are some options :


For Option 2 we can perform a safe-upgrade of the following file, or see option 3 to add $validator->getHostnameValidator()->setValidateTld(false);, copying it from :

/lib/Zend/Validate/Hostname.php

to :

/app/code/local/Zend/Validate/Hostname.php

Then look for this block of code, and just comment the three lines :

if (!in_array($this->_tld, $this->_validTlds)) {
  // $this->_error(self::UNKNOWN_TLD);
  // $status = false;
  // break;
}

For Option 3 we can perform a safe-upgrade of the following file, copying it from :

app/code/core/Mage/Eav/Model/Attribute/Data/Abstract.php

to :

/app/code/local/Mage/Eav/Model/Attribute/Data/Abstract.php

Then replace this code :

$validator = new Zend_Validate_EmailAddress();

by :

// 1. we check mx record
$validator = new Zend_Validate_EmailAddress(
    array(
      'allow' => Zend_Validate_Hostname::ALLOW_DNS,
      'mx'    => true
    )
);
// 2. we remove TLD validation :
$validator->getHostnameValidator()->setValidateTld(false);

Do not forget to look for every call of the Zend_Validate_EmailAddress class that can be used in community or custom extensions (e.g : onestepcheckout).

Upvotes: 6

Aleksey Razbakov
Aleksey Razbakov

Reputation: 634

There are new generic Top Level Domain extension (gTLDs). These are going to cause issues with Zend Validator.

The best fix is to disable hostname validation in Magento and leave it up to the end user to correctly enter a domain name:

find Mage_Eav_Model_Attribute_Data_Abstract and

change

$validator = new Zend_Validate_EmailAddress();

to

$validator = new Zend_Validate_EmailAddress(array('domain'=>false));

Or you can simply install patch via composer.

Upvotes: 0

Related Questions