diff --git a/lib/Service/DomainService.php b/lib/Service/DomainService.php index eb62841dfe346e78d3dc9514749cf2976bf68136..ad7b4804f660557b540333ad4dfd49fc23557e58 100644 --- a/lib/Service/DomainService.php +++ b/lib/Service/DomainService.php @@ -72,8 +72,17 @@ class DomainService { * Add a custom disposable domain to the list. */ public function addCustomDisposableDomain(string $domain, IL10N $l, array $relatedDomains = []): void { + // Sanitize the domain and related domains to remove control characters + $cleanDomain = preg_replace('/[\x00-\x1F\x7F]/', '', $domain); + $cleanRelatedDomains = array_map(fn ($relatedDomain) => preg_replace('/[\x00-\x1F\x7F]/', '', $relatedDomain), $relatedDomains); + + // Get existing domains from the file $domains = $this->getDomainsFromFile(self::DISPOSABLE_DOMAINS_FILE, $l); - $newDomains = array_unique(array_merge($domains, [$domain], $relatedDomains)); + + // Merge, deduplicate, and sanitize + $newDomains = array_unique(array_merge($domains, [$cleanDomain], $cleanRelatedDomains)); + + // Save the updated list to the file $this->saveDomainsToFile(self::DISPOSABLE_DOMAINS_FILE, $newDomains); }