testTLD incorrectly reports valid TLDs with subdomains as invalid (e.g., a.example.com)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start with source/fix.common.problems/usr/local/emhttp/plugins/fix.common.problems/include/tests.php and inspect the testTLD function and its current LOCAL_TLD validation. Verify cases such as a.example.com and invalid labels, then confirm that valid labels and the full-length limit are accepted or rejected according to the issue's stated DNS rules.
Written by the indexing model from the issue text.
Description
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:
testTLDruns 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.comcause 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
- Bug found in commit: 7056e6e452c27ae690a00f5b2dba1e164de40939
Let me know if a patch or PR is desired!
- Dominant language
- PHP
- Stars
- 0
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from unraid/fix.common.problems
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
unraid/fix.common.problems#4 · 1 comment ·
All issues in unraid/fix.common.problems
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
getgrav/grav-plugin-api#45 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
RSS-Bridge/rss-bridge#5098 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
phingofficial/phing#2025 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
silverstripe/developer-docs#911 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100