Skip to content

Commit

Permalink
Fix: Invalid site domain validation for domains with umlauts (ä, ö, ü…
Browse files Browse the repository at this point in the history
…, etc.) (pimcore#17734)

* Fix: Invalid site domain validation for domains with umlauts (ä, ö, ü, etc.)

* Fix sonarcloud
  • Loading branch information
blankse authored Oct 18, 2024
1 parent d8da787 commit 159fe18
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function loadInternal(array $config, ContainerBuilder $container): void
// when not an env variable, check if the domain is valid
if (
!str_starts_with($domain, 'env_') &&
!filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
!filter_var(idn_to_ascii($domain), FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
) {
throw new InvalidArgumentException(sprintf('Invalid main domain name "%s"', $domain));
}
Expand Down
5 changes: 4 additions & 1 deletion lib/SystemSettingsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ private function prepareSystemConfig(array $values): array
$this->checkFallbackLanguageLoop($sourceLang, $fallbackLanguages);
}

if ($values['general.domain'] && !filter_var($values['general.domain'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
if (
$values['general.domain'] &&
!filter_var(idn_to_ascii($values['general.domain']), FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
) {
throw new InvalidArgumentException(sprintf('Invalid main domain name "%s"', $values['general.domain']));
}

Expand Down
9 changes: 7 additions & 2 deletions models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,16 @@ public function setDomains(array|string $domains): static
array_map(static function ($domain) {
//replace all wildcards with a placeholder dummy string
$wildCardLessDomain = str_replace('*', 'anystring', $domain);
if ($wildCardLessDomain && !filter_var($wildCardLessDomain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
if (
$wildCardLessDomain &&
!filter_var(idn_to_ascii($wildCardLessDomain), FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
) {
throw new InvalidArgumentException(sprintf('Invalid domain name "%s"', $domain));
}
}, $domains);
$this->domains = $domains;
} else {
$this->domains = [];
}

return $this;
Expand Down Expand Up @@ -315,7 +320,7 @@ public function getLocalizedErrorDocuments(): array

public function setMainDomain(string $mainDomain): void
{
if ($mainDomain && !filter_var($mainDomain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
if ($mainDomain && !filter_var(idn_to_ascii($mainDomain), FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
throw new InvalidArgumentException(sprintf('Invalid main domain name "%s"', $mainDomain));
}
$this->mainDomain = $mainDomain;
Expand Down

0 comments on commit 159fe18

Please sign in to comment.