Skip to content

[HTTP] Wrong Request::baseUrl when request matches PHP SCRIPT_FILENAME #37995

Closed
@apfelbox

Description

@apfelbox

Symfony version(s) affected: 5.1.2

Description

  • My document root is /var/www/photos/public.
  • front controller at /var/www/photos/public/index.php.
  • I try to request a path called /php/index.php (it's a route with this exact path).

I have the following parameters in my $_SERVER:

[
"DOCUMENT_ROOT" => "/var/www/photos/public",
"DOCUMENT_URI" => "index.php",
"PATH_INFO" => "",
"PHP_SELF" => "index.php",
"REQUEST_URI" => "/php/index.php",
"SCRIPT_FILENAME" => "/var/www/photos/public/index.php",
"SCRIPT_NAME" => "index.php",
]

So, as the app is installed directly under the domain, the base url should always be empty.
However.. as this (see below) will never be true (as the base is index.php, as well as the base of the request url), it will always be set incorrectly.

https://github.com/symfony/symfony/blob/v5.1.2/src/Symfony/Component/HttpFoundation/Request.php#L1852-L1856

How to reproduce
This would be a (currently failing) test case to handle this issue:

use Symfony\Component\HttpFoundation\Request;

$request = new Request(
	$query = [],
	$request = [], 
	$attributes = [], 
	$cookies = [], 
	$files = [], 
	$server = [
		"DOCUMENT_ROOT" => "/var/www/photos/public",
		"DOCUMENT_URI" => "index.php",
		"PATH_INFO" => "",
		"PHP_SELF" => "index.php",
		"REQUEST_URI" => "/php/index.php",
		"SCRIPT_FILENAME" => "/var/www/photos/public/index.php",
		"SCRIPT_NAME" => "index.php",
	]
);

assert("" === $request->getBaseUrl());

Please note that if you change the REQUEST_URI above to "REQUEST_URI" => "/php/index2.php", it will work correctly.

Possible Solution
I have absolutely no overview around all the weird edge cases of this exact method, I only know that this is an issue and it should possibly be fixed?
Sorry to deliver another edge case :(

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions