Skip to content

Commit

Permalink
[BUGFIX] Let GeneralUtility::getIndpEnv() return string more often
Browse files Browse the repository at this point in the history
We unfortunately still didn't manage to drop remaining
usages of GeneralUtility::getIndpEnv() and deprecate
the method in v11.

So we have to harden it a bit towards better PHP
compatibility: The method states it always returns
string, but it doesn't. Especially HTTP_HOST and
REMOTE_ADDR tend to return null. This isn't critical
since that's usually just triggered by tests, but
still, these calls should fall back to empty string
instead of null. The return values are often further
processed with string related methods, both in
getIndpEnv() itself, in other consumers, and in
other helper methods like cmpIp(). It absolutely
makes sense to return empty string over null in
lowlevel getIndpEnv() directly.

Resolves: #95764
Releases: master
Change-Id: I008452bb8445f1c23f634312d205102e4bb7602d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/71966
Tested-by: core-ci <typo3@b13.com>
Tested-by: Jochen <rothjochen@gmail.com>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Jochen <rothjochen@gmail.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
lolli42 authored and maddy2101 committed Oct 25, 2021
1 parent cf1a890 commit 3e27e56
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions typo3/sysext/core/Classes/Utility/GeneralUtility.php
Expand Up @@ -2508,10 +2508,10 @@ public static function getIndpEnv($getEnvName)
}
break;
case 'TYPO3_REV_PROXY':
$retVal = self::cmpIP($_SERVER['REMOTE_ADDR'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP']);
$retVal = self::cmpIP($_SERVER['REMOTE_ADDR'] ?? '', $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP']);
break;
case 'REMOTE_ADDR':
$retVal = $_SERVER['REMOTE_ADDR'] ?? null;
$retVal = $_SERVER['REMOTE_ADDR'] ?? '';
if (self::cmpIP($retVal, $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP'] ?? '')) {
$ip = self::trimExplode(',', $_SERVER['HTTP_X_FORWARDED_FOR'] ?? '');
// Choose which IP in list to use
Expand All @@ -2536,7 +2536,7 @@ public static function getIndpEnv($getEnvName)
break;
case 'HTTP_HOST':
// if it is not set we're most likely on the cli
$retVal = $_SERVER['HTTP_HOST'] ?? null;
$retVal = $_SERVER['HTTP_HOST'] ?? '';
if (isset($_SERVER['REMOTE_ADDR']) && static::cmpIP($_SERVER['REMOTE_ADDR'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP'])) {
$host = self::trimExplode(',', $_SERVER['HTTP_X_FORWARDED_HOST'] ?? '');
// Choose which host in list to use
Expand Down Expand Up @@ -2634,7 +2634,7 @@ public static function getIndpEnv($getEnvName)
$retVal = substr(self::getIndpEnv('TYPO3_REQUEST_URL'), strlen(self::getIndpEnv('TYPO3_SITE_URL')));
break;
case 'TYPO3_SSL':
$proxySSL = trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxySSL'] ?? null);
$proxySSL = trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxySSL'] ?? '');
if ($proxySSL === '*') {
$proxySSL = $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP'];
}
Expand Down

0 comments on commit 3e27e56

Please sign in to comment.