www/caddy: Fix input validation - allow wildcard domains and base domains at the same time (#3915)

* Update Caddy.php - Remove validation that checks for conflicts between wildcard and base domain

If a user creates a wildcard domain, the base domain won't be represented under it, so the base domain has to be created additionally. This validation prevented this from happening, even though it's a valid configuration.

* Update pkg-descr - included fix
This commit is contained in:
Monviech
2024-04-16 15:22:31 +02:00
committed by GitHub
parent 8f2490aa8a
commit 7e6bc0ae49
2 changed files with 1 additions and 37 deletions
+1
View File
@@ -37,6 +37,7 @@ Plugin Changelog
* Fix: Move selectpicker empty option to model in general.volt, using BlankDesc. This fixes the option IPv4+IPv6 not appearing in Dynamic DNS.
* Add: Simple Load Balancing support with the default random policy, by allowing to add multiple Upstream Domains in Handlers.
* Add: Passive Health check for load balancing (Upstream Fail Duration) in Handlers.
* Fix: Input validation so a base domain like "example.com" and a wildcard domain like "*.example.com" can now be created at the same time in domains.
1.5.3
@@ -107,41 +107,6 @@ class Caddy extends BaseModel
}
}
// 4. Check for conflicts between wildcard and base domains
private function checkForWildcardAndBaseDomainConflicts($domains, $messages)
{
$domainList = [];
foreach ($domains as $domain) {
if ((string) $domain->enabled === '1') {
$domainName = (string) $domain->FromDomain;
$domainList[$domainName] = true;
// Check for wildcard or base domain conflict
if (str_starts_with($domainName, '*.')) {
$baseDomain = substr($domainName, 2);
if (isset($domainList[$baseDomain])) {
$key = $domain->__reference; // Dynamic key based on domain reference
$messages->appendMessage(new Message(
"Invalid domain configuration: Cannot create wildcard domain '$domainName' because base domain '$baseDomain' exists.",
$key . ".FromDomain", // Use dynamic key for message referencing
"WildcardBaseConflict"
));
}
} else {
$wildcardDomain = '*.' . $domainName;
if (isset($domainList[$wildcardDomain])) {
$key = $domain->__reference; // Dynamic key based on domain reference
$messages->appendMessage(new Message(
"Invalid domain configuration: Cannot create base domain '$domainName' because wildcard domain '$wildcardDomain' exists.",
$key . ".FromDomain", // Use dynamic key for message referencing
"BaseWildcardConflict"
));
}
}
}
}
}
// Perform the actual validation
public function performValidation($validateFullModel = false)
{
@@ -152,8 +117,6 @@ class Caddy extends BaseModel
$this->checkForUniquePortCombos($this->reverseproxy->subdomain->iterateItems(), $messages, 'subdomain');
// 3. Check that subdomains are under a wildcard or exact domain
$this->checkSubdomainsAgainstDomains($this->reverseproxy->subdomain->iterateItems(), $this->reverseproxy->reverse->iterateItems(), $messages);
// 4. Check for conflicts between wildcard and base domains
$this->checkForWildcardAndBaseDomainConflicts($this->reverseproxy->reverse->iterateItems(), $messages);
return $messages;
}