2 declare(strict_types = 1);
293 public function __construct(array $serverParams, array $configuration,
string $pathThisScript,
string $pathSite)
314 $this->pathInfo = $serverParams[
'PATH_INFO'] ??
'';
315 $this->httpReferer = $serverParams[
'HTTP_REFERER'] ??
'';
316 $this->httpUserAgent = $serverParams[
'HTTP_USER_AGENT'] ??
'';
317 $this->httpAcceptEncoding = $serverParams[
'HTTP_ACCEPT_ENCODING'] ??
'';
318 $this->httpAcceptLanguage = $serverParams[
'HTTP_ACCEPT_LANGUAGE'] ??
'';
319 $this->remoteHost = $serverParams[
'REMOTE_HOST'] ??
'';
320 $this->queryString = $serverParams[
'QUERY_STRING'] ??
'';
540 $httpHost = $serverParams[
'HTTP_HOST'] ??
'';
544 $xForwardedHostArray = GeneralUtility::trimExplode(
',', $serverParams[
'HTTP_X_FORWARDED_HOST'] ??
'',
true);
545 $xForwardedHost =
'';
547 if (!empty($xForwardedHostArray)) {
548 $configuredReverseProxyHeaderMultiValue = trim($configuration[
'reverseProxyHeaderMultiValue'] ??
'');
554 if ($configuredReverseProxyHeaderMultiValue ===
'last') {
555 $xForwardedHost = array_pop($xForwardedHostArray);
556 } elseif ($configuredReverseProxyHeaderMultiValue ===
'first') {
557 $xForwardedHost = array_shift($xForwardedHostArray);
560 if ($xForwardedHost) {
564 if (!GeneralUtility::isAllowedHostHeaderValue(
$httpHost)) {
565 throw new \UnexpectedValueException(
566 'The current host header value does not match the configured trusted hosts pattern!'
567 .
' Check the pattern defined in $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'trustedHostsPattern\']'
568 .
' and adapt it, if you want to allow the current host header \'' .
$httpHost .
'\' for your installation.
',
583 protected static function determineHttps(array $serverParams, array $configuration): bool
586 $configuredProxySSL = trim($configuration['reverseProxySSL
'] ?? '');
587 if ($configuredProxySSL === '*
') {
588 $configuredProxySSL = trim($configuration['reverseProxyIP
'] ?? '');
590 $httpsParam = (string)($serverParams['HTTPS
'] ?? '');
591 if (GeneralUtility::cmpIP(trim($serverParams['REMOTE_ADDR
'] ?? ''), $configuredProxySSL)
592 || ($serverParams['SSL_SESSION_ID
'] ?? '')
593 // https://secure.php.net/manual/en/reserved.variables.server.php
594 // "Set to a non-empty value if the script was queried through the HTTPS protocol."
595 || ($httpsParam !== '' && $httpsParam !== 'off
' && $httpsParam !== '0
')
611 protected static function determineScriptName(array $serverParams, array $configuration, bool $isHttps, bool $isBehindReverseProxy): string
613 // see https://forge.typo3.org/issues/89312
614 // When using a CGI wrapper to dispatch the PHP process `ORIG_SCRIPT_NAME`
615 // contains the name of the wrapper script (which is most probably outside
616 // the TYPO3's project root) and leads to invalid prefixes, e.g. resolving
619 $possiblePathInfo = ($serverParams[
'ORIG_PATH_INFO'] ??
'') ?: ($serverParams[
'PATH_INFO'] ??
'');
620 $possibleScriptName = ($serverParams[
'ORIG_SCRIPT_NAME'] ??
'') ?: ($serverParams[
'SCRIPT_NAME'] ??
'');
623 : $possibleScriptName;
626 if (
$isHttps && !empty($configuration[
'reverseProxyPrefixSSL'])) {
628 } elseif (!empty($configuration[
'reverseProxyPrefix'])) {
648 $proxyPrefixApplied =
false;
649 if (!empty($configuration[
'requestURIvar'])) {
653 list($firstLevel, $secondLevel) = GeneralUtility::trimExplode(
'|', $configuration[
'requestURIvar'],
true);
655 } elseif (empty($serverParams[
'REQUEST_URI'])) {
657 $queryString = !empty($serverParams[
'QUERY_STRING']) ?
'?' . $serverParams[
'QUERY_STRING'] :
'';
659 $proxyPrefixApplied =
true;
662 $requestUri =
'/' . ltrim($serverParams[
'REQUEST_URI'],
'/');
666 if (
$isHttps && !empty($configuration[
'reverseProxyPrefixSSL'])) {
668 } elseif (!empty($configuration[
'reverseProxyPrefix'])) {
687 $ip = GeneralUtility::trimExplode(
',', $serverParams[
'HTTP_X_FORWARDED_FOR'] ??
'',
true);
689 $configuredReverseProxyHeaderMultiValue = trim($configuration[
'reverseProxyHeaderMultiValue'] ??
'');
690 if (!empty($ip) && $configuredReverseProxyHeaderMultiValue ===
'last') {
691 $ip = array_pop($ip);
692 } elseif (!empty($ip) && $configuredReverseProxyHeaderMultiValue ===
'first') {
693 $ip = array_shift($ip);
697 if (GeneralUtility::validIP($ip)) {
713 return GeneralUtility::cmpIP(trim($serverParams[
'REMOTE_ADDR'] ??
''), trim($configuration[
'reverseProxyIP'] ??
''));
726 return $httpHostBracketPosition !==
false ? substr(
$httpHost, 0, $httpHostBracketPosition + 1) : array_shift($httpHostParts);
738 return strlen(
$httpHost) > strlen($httpHostOnly) ? (int)substr(
$httpHost, strlen($httpHostOnly) + 1) : 0;
759 foreach ($scriptNameArray as $segmentNumber => $segment) {
760 if ((
string)$scriptFilenameArray[$segmentNumber] === (
string)$segment) {
766 $commonEnd = strrev(implode(
'/', $path));
767 if ((
string)$commonEnd !==
'') {
783 if (defined(
'TYPO3_PATH_WEB')) {
787 $pathThisScriptDir = substr(dirname($pathThisScript), strlen($pathSite)) .
'/';