Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using IDN domain names, it is easy to reach the limit and throw exception Regex::DOMAIN_OR_SUBDOMAIN #1

Open
xiaohuilam opened this issue Jun 19, 2023 · 6 comments

Comments

@xiaohuilam
Copy link

if (!preg_match(Regex::DOMAIN_OR_SUBDOMAIN, $hostName)) {
throw new DnsHandlerException(
$hostnameErrorInfo . ' format! (characters "A-Za-z0-9.-", max length 63 chars allowed)',
DnsHandlerException::HOSTNAME_FORMAT_INVALID
);
}

@bluelibraries
Copy link
Owner

Thank you very much for notifying.
Let's increase it to 255.
What do you think?

@bluelibraries
Copy link
Owner

I'm on it.

@xiaohuilam
Copy link
Author

Thank you very much for notifying. Let's increase it to 255. What do you think?

Perhaps okay, but why there's a limitation for hostname length?

xiaohuilam added a commit to anquanssl/dns that referenced this issue Oct 1, 2023
@james2001
Copy link

Hello

This domain is valide xn--c1aafynu.xn--c1avg.xn--p1acf, but the regex doesn't match
because the xn part is not in the TDL -> ^(([\w\d_-]+){1,63}.)+([\w\d_-]+){2,63}$

Why the lib, don't use https://www.php.net/manual/en/filter.filters.validate.php

@james2001
Copy link

@xiaohuilam can you test #3 ?

@xiaohuilam
Copy link
Author

xiaohuilam commented Mar 12, 2024

@xiaohuilam can you test #3 ?

@james2001 I think this is better.

filter_var($hostName, FILTER_VALIDATE_DOMAIN)

because it will return false if $hostName = '_dnsauth.test.com' in your code:

$hostName = '_dnsauth.test.com';
var_dump(filter_var($hostName, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)); // it returns `false`, and unexpected.

_dnsauth is digicert's domain validation hostname prefix, it's allowed to be created as dns host for mostly dns service providers.

and, please mention @bluelibraries for more review because he is the owner of this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants