php-whois icon indicating copy to clipboard operation
php-whois copied to clipboard

Incorrect handling of domain free response of .nl whois

Open tofra opened this issue 4 years ago • 4 comments

PHP-Whois version: 4.0.0

PHP version: 7.4.13

Description I'm searching if a .nl domain is free, and php-whois isn't able to correctly tell me if it's free. The things I observe is that when you too often do a whois request, the server response with "you have reached the limit of requests per second" (not the exact text), php-whois will return null when doing $whois->loadDomainInfo('notanexistingdomain.nl'). But it also returns null when the domain is free. Also it will always do two requests to the whoisAPI, one with $query notanexistingdomain.nl and the second one with =notanexistingdomain.nl The API returns notexistingnldomain.nl is free on the first request, and then the second request (which is initiated from https://github.com/io-developer/php-whois/blob/master/src/Iodev/Whois/Modules/Tld/TldModule.php#L210) with $query =notanexistingdomain.nl which get the response of the API Error: invalid domain name

How to reproduce
$result = $whois->loadDomainInfo('notanexistingdomain.nl'). It should not return null, and it should not execute 2 requests (aka should not come here https://github.com/io-developer/php-whois/blob/master/src/Iodev/Whois/Modules/Tld/TldModule.php#L210)

tofra avatar Apr 04 '21 20:04 tofra

Note:

    ["text"]=>
    string(74) "whois.domain-registry.nl: maximum number of requests per second exceeded
"

io-developer avatar Jul 13 '21 20:07 io-developer

@io-developer Can you please guide me where I should look to fix it, so I can create a PR? My issue is the same like mentioned in https://github.com/io-developer/php-whois/issues/132#issuecomment-722947231

I assume that we need to build something that will throw an exception when the "text" matches a specific text (like maximum number of requests per second exceeded)

tofra avatar Oct 13 '21 23:10 tofra

Should we create a new Tld\Parser? To handle "error codes", and then throw exception?

tofra avatar Oct 13 '21 23:10 tofra

At the moment a check is done on validateResponse method on loaders:

https://github.com/io-developer/php-whois/blob/21454dfdf2979d062f80e428e53e0e9f9981add6/src/Iodev/Whois/Loaders/SocketLoader.php#L85

https://github.com/io-developer/php-whois/blob/21454dfdf2979d062f80e428e53e0e9f9981add6/src/Iodev/Whois/Loaders/CurlLoader.php#L117

but the regular expression probably refers to the message of a single TLD, it should be extended to handle more cases of whois servers error messages, quite precisely to avoid false positives.

There are some regexps in the json and others in the PHP code, a more complete refactoring should put them all in one place, but IMHO that's too much work given the few developers on the project.

bessone avatar Nov 25 '21 17:11 bessone