diff --git a/src/Tech/Service/EmailVerifier.php b/src/Tech/Service/EmailVerifier.php index aa3aef9..d6ed9c3 100644 --- a/src/Tech/Service/EmailVerifier.php +++ b/src/Tech/Service/EmailVerifier.php @@ -71,6 +71,8 @@ class EmailVerifier $parts = parse_url($siteBaseUrl); if (isset($parts['host'])) { $request->headers->set('HOST', $parts['host']); + $request->server->set('SERVER_NAME', $parts['host']); + $request->server->set('SERVER_ADDR', $parts['host']); } if (isset($parts['scheme'])) { $request->server->set('HTTPS', 'https' === $parts['scheme'] ? 'on' : 'off'); @@ -93,6 +95,35 @@ class EmailVerifier } } + // Ensure the host is in the trusted hosts list to avoid validation failure in getHost() + if (isset($parts['host'])) { + try { + $request->getHost(); + } catch (\Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException) { + // Host is not trusted, add it temporarily if we can't bypass it. + // Since trustedHostPatterns is static, we can use Request::setTrustedHosts. + // We should append to existing ones if possible. + $reflectionRequest = new \ReflectionClass(Request::class); + $propPatterns = $reflectionRequest->getProperty('trustedHostPatterns'); + $propPatterns->setAccessible(true); + $currentPatterns = $propPatterns->getValue(); + + $newPattern = '{^' . preg_quote($parts['host']) . '$}i'; + if (!in_array($newPattern, $currentPatterns)) { + Request::setTrustedHosts(array_merge(['^' . preg_quote($parts['host']) . '$'], [/* placeholder to trigger re-calculation of patterns from strings */])); + // Actually, setTrustedHosts takes an array of patterns (strings). + // Let's just use a simple approach. + $host = $parts['host']; + Request::setTrustedHosts(array_unique(array_merge(['^localhost$', '^' . preg_quote($host) . '$'], [$_ENV['TRUSTED_HOSTS'] ?? '^.*$']))); + } + + // Reset isHostValid again after changing trusted hosts + $propHostValid = $reflection->getProperty('isHostValid'); + $propHostValid->setAccessible(true); + $propHostValid->setValue($request, true); + } + } + if (isset($parts['path'])) { $baseUrl = rtrim($parts['path'], '/'); $request->server->set('SCRIPT_NAME', $baseUrl . '/index.php');