Skip to content

Commit

Permalink
[BUGFIX] Consider CGI wrapper for NormalizedParams->getSiteUrl()
Browse files Browse the repository at this point in the history
When using a CGI wrapper to dispatch the PHP process `ORIG_SCRIPT_NAME`
contains the name of the wrapper script (which is most probably outside
the TYPO3's project root) and leads to invalid prefixes, e.g. resolving
the `siteUrl` incorrectly as `http://ip10.local/fcgi/` instead of
actual `http://ip10.local/`.

Resolves: #89312
Releases: master, 9.5
Change-Id: Ib0732344deb0f2e71e06a4a1929bb712cd4f2239
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63602
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Tested-by: Susanne Moog <look@susi.dev>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Susanne Moog <look@susi.dev>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
ohader authored and bmack committed Mar 8, 2020
1 parent d577b18 commit 045d4dc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 22 additions & 0 deletions typo3/sysext/core/Classes/Core/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
*/
class Environment
{
/**
* A list of supported CGI server APIs
* @var array
*/
protected static $supportedCgiServerApis = [
'fpm-fcgi',
'cgi',
'isapi',
'cgi-fcgi',
'srv', // HHVM with fastcgi
];

protected static $cli;
protected static $composerMode;
protected static $context;
Expand Down Expand Up @@ -265,6 +277,16 @@ public static function isUnix(): bool
return self::$os === 'UNIX';
}

/**
* Returns true if the server is running on a list of supported CGI server APIs.
*
* @return bool
*/
public static function isRunningOnCgiServer(): bool
{
return in_array(PHP_SAPI, self::$supportedCgiServerApis, true);
}

/**
* Returns the currently configured Environment information as array.
*
Expand Down
12 changes: 11 additions & 1 deletion typo3/sysext/core/Classes/Http/NormalizedParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,17 @@ protected static function determineScriptName(
bool $isHttps,
bool $isBehindReverseProxy
): string {
$scriptName = ($serverParams['ORIG_SCRIPT_NAME'] ?? '') ?: ($serverParams['SCRIPT_NAME'] ?? '');
// see https://forge.typo3.org/issues/89312
// When using a CGI wrapper to dispatch the PHP process `ORIG_SCRIPT_NAME`
// contains the name of the wrapper script (which is most probably outside
// the TYPO3's project root) and leads to invalid prefixes, e.g. resolving
// the `siteUrl` incorrectly as `http://ip10.local/fcgi/` instead of
// actual `http://ip10.local/`
$possiblePathInfo = ($serverParams['ORIG_PATH_INFO'] ?? '') ?: ($serverParams['PATH_INFO'] ?? '');
$possibleScriptName = ($serverParams['ORIG_SCRIPT_NAME'] ?? '') ?: ($serverParams['SCRIPT_NAME'] ?? '');
$scriptName = Environment::isRunningOnCgiServer() && $possiblePathInfo
? $possiblePathInfo
: $possibleScriptName;
if ($isBehindReverseProxy) {
// Add a prefix if TYPO3 is behind a proxy: ext-domain.com => int-server.com/prefix
if ($isHttps && !empty($configuration['reverseProxyPrefixSSL'])) {
Expand Down

0 comments on commit 045d4dc

Please sign in to comment.