Skip to content

Fix # 34866 - base path discovery with autoindex #34868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1944,10 +1944,18 @@ protected function prepareBaseUrl()
$truncatedRequestUri = substr($requestUri, 0, $pos);
}

$basename = basename($baseUrl);
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
// no match whatsoever; set it blank
return '';
$autoindexRemoved = false;
if (empty(basename($baseUrl)) || !strpos(rawurldecode($truncatedRequestUri), basename($baseUrl))) {
// fix "index.php" autoindex 1/2, fix #34866
if ('/index.php' === substr($baseUrl, -10)) {
$baseUrl = substr($baseUrl, 0, -9);
$autoindexRemoved = true;
}

if (empty(basename($baseUrl)) || !strpos(rawurldecode($truncatedRequestUri), basename($baseUrl))) {
// no match whatsoever; set it blank
return '';
}
}

// If using mod_rewrite or ISAPI_Rewrite strip the script filename
Expand All @@ -1957,6 +1965,10 @@ protected function prepareBaseUrl()
$baseUrl = substr($requestUri, 0, $pos + \strlen($baseUrl));
}

if ($autoindexRemoved) {
$baseUrl .= 'index.php';
}

return rtrim($baseUrl, '/'.\DIRECTORY_SEPARATOR);
}

Expand Down Expand Up @@ -2009,6 +2021,12 @@ protected function preparePathInfo()
return $requestUri;
}

// fix "index.php" autoindex 2/2, fix #34866
if (\strlen($baseUrl) >= 10 && 0 !== strpos($requestUri, $baseUrl)
&& '/index.php' === substr($baseUrl, -10)
&& 0 === strpos($requestUri, substr($baseUrl, 0, -9))) {
$baseUrl = substr($baseUrl, 0, -10);
}
$pathInfo = substr($requestUri, \strlen($baseUrl));
if (false === $pathInfo || '' === $pathInfo) {
// If substr() returns false then PATH_INFO is set to an empty string
Expand Down