edit: 100% Copilot-generated. I don't know why it doesn't say that it was authored by copilot, but it was.
edit2: When this is fixed, it's probably worth adding the maximum length check of 255 octets too.
Bug Report
Affected Function: testTLD in tests.php
Problem
When the LOCAL_TLD is set to a value like a.example.com, the function currently splits on the dot and only checks the first label (e.g., a). Since the code enforces a minimum length of 2 for the TLD, any TLD where the first label is less than 2 characters (as in a.example.com) is incorrectly flagged as invalid, even though it is a valid FQDN.
What happens:
testTLD runs this logic:
$TLDmain = explode('.', trim($unRaidVars['LOCAL_TLD']))[0];
if (strlen($TLDmain) < 2 || strlen($TLDmain) > 63 || preg_match('/[^a-zA-Z0-9\-]+/m', $TLDmain)) ...
- This only validates the first label of the TLD, not the full TLD or all its labels.
- Inputs like
a.example.com cause false positives (invalid warning) even though each label is otherwise valid.
Expected Behavior
- Each label in the TLD (split by
.) should be checked against DNS rules:
- Each label: 1-63 chars, only [a-zA-Z0-9-]
- Whole TLD: up to 253 chars (DNS)
- Dots should not be treated as invalid
- No unnecessary warning for valid subdomains like
a.example.com
Proposed Fix
Replace this block:
$TLDmain = explode('.', trim($unRaidVars['LOCAL_TLD']))[0];
if (!$unRaidVars['LOCAL_TLD'])
addWarning(...);
elseif (strlen($TLDmain) < 2 || strlen($TLDmain) > 63 || preg_match('/[^a-zA-Z0-9\-]+/m', $TLDmain))
addWarning(...);
With:
if (!$unRaidVars['LOCAL_TLD']) {
addWarning(...);
} else {
$tld_labels = explode('.', trim($unRaidVars['LOCAL_TLD']));
$invalid = false;
foreach ($tld_labels as $label) {
if (strlen($label) < 1 || strlen($label) > 63 || preg_match('/[^a-zA-Z0-9\-]/', $label)) {
$invalid = true;
break;
}
}
if ($invalid || strlen($unRaidVars['LOCAL_TLD']) > 253) {
addWarning(...);
}
}
References
Impact
- Users with valid FQDNs including subdomains may see incorrect warnings about invalid TLDs.
Environment
Let me know if a patch or PR is desired!
edit: 100% Copilot-generated. I don't know why it doesn't say that it was authored by copilot, but it was.
edit2: When this is fixed, it's probably worth adding the maximum length check of 255 octets too.
Bug Report
Affected Function:
testTLDintests.phpProblem
When the LOCAL_TLD is set to a value like
a.example.com, the function currently splits on the dot and only checks the first label (e.g.,a). Since the code enforces a minimum length of 2 for the TLD, any TLD where the first label is less than 2 characters (as ina.example.com) is incorrectly flagged as invalid, even though it is a valid FQDN.What happens:
testTLDruns this logic:a.example.comcause false positives (invalid warning) even though each label is otherwise valid.Expected Behavior
.) should be checked against DNS rules:a.example.comProposed Fix
Replace this block:
With:
References
Impact
Environment
Let me know if a patch or PR is desired!