From 7e6bc0ae490a90a195d2b07f5d2a09805be2fab4 Mon Sep 17 00:00:00 2001 From: Monviech <79600909+Monviech@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:22:31 +0200 Subject: [PATCH] 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 --- www/caddy/pkg-descr | 1 + .../mvc/app/models/OPNsense/Caddy/Caddy.php | 37 ------------------- 2 files changed, 1 insertion(+), 37 deletions(-) diff --git a/www/caddy/pkg-descr b/www/caddy/pkg-descr index 452ecabe8..c3c9030dc 100644 --- a/www/caddy/pkg-descr +++ b/www/caddy/pkg-descr @@ -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 diff --git a/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.php b/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.php index 953f284fb..531391213 100644 --- a/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.php +++ b/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.php @@ -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; }