Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions UPGRADE-7.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ HttpFoundation
* Add argument `$subtypeFallback` to `Request::getFormat()`
* Deprecate using `Request::sendHeaders()` after headers have already been sent; use a `StreamedResponse` instead
* Deprecate method `Request::get()`, use properties `->attributes`, `query` or `request` directly instead
* Deprecate HTTP method override for methods GET, HEAD, CONNECT and TRACE; it will be ignored in Symfony 8.0

HttpKernel
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function testOpeningDisallowedPaths($path, $isAllowed)
$controller = new ProfilerController($urlGenerator, $profiler, $twig, [], null, __DIR__.'/../..');

try {
$response = $controller->openAction(Request::create('/_wdt/open', Request::METHOD_GET, ['file' => $path]));
$response = $controller->openAction(Request::create('/_wdt/open', 'GET', ['file' => $path]));
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($isAllowed);
} catch (NotFoundHttpException $e) {
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpFoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CHANGELOG
* Deprecate using `Request::sendHeaders()` after headers have already been sent; use a `StreamedResponse` instead
* Deprecate method `Request::get()`, use properties `->attributes`, `query` or `request` directly instead
* Make `Request::createFromGlobals()` parse the body of PUT, DELETE, PATCH and QUERY requests
* Deprecate HTTP method override for methods GET, HEAD, CONNECT and TRACE; it will be ignored in Symfony 8.0

7.3
---
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,10 @@ public function getMethod(): string

$method = strtoupper($method);

if (\in_array($method, ['GET', 'HEAD', 'CONNECT', 'TRACE'], true)) {
trigger_deprecation('symfony/http-foundation', '7.4', 'HTTP method override is deprecated for methods GET, HEAD, CONNECT and TRACE; it will be ignored in Symfony 8.0.', $method);
}

if (self::$allowedHttpMethodOverride && !\in_array($method, self::$allowedHttpMethodOverride, true)) {
return $this->method;
}
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,18 @@ public function testGetSetMethod()
$this->assertSame('POST', $request->getMethod(), '->getMethod() returns the request method if invalid type is defined in query');
}

#[IgnoreDeprecations]
#[Group('legacy')]
public function testUnsafeMethodOverride()
{
$request = new Request();
$request->setMethod('POST');
$request->headers->set('X-HTTP-METHOD-OVERRIDE', 'get');

$this->expectUserDeprecationMessage('Since symfony/http-foundation 7.4: HTTP method override is deprecated for methods GET, HEAD, CONNECT and TRACE; it will be ignored in Symfony 8.0.');
$this->assertSame('GET', $request->getMethod());
}

#[DataProvider('getClientIpsProvider')]
public function testGetClientIp($expected, $remoteAddr, $httpForwardedFor, $trustedProxies)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function needsParsing(Response $response): bool

public function handle(HttpCache $cache, string $uri, string $alt, bool $ignoreErrors): string
{
$subRequest = Request::create($uri, Request::METHOD_GET, [], $cache->getRequest()->cookies->all(), [], $cache->getRequest()->server->all());
$subRequest = Request::create($uri, 'GET', [], $cache->getRequest()->cookies->all(), [], $cache->getRequest()->server->all());

try {
$response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ public function testConfigKeyForQueryString()
$argument = new ArgumentMetadata('filtered', QueryPayload::class, false, false, null, false, [
MapQueryString::class => new MapQueryString(key: 'value'),
]);
$request = Request::create('/', Request::METHOD_GET, ['value' => ['page' => 1.0]]);
$request = Request::create('/', 'GET', ['value' => ['page' => 1.0]]);

$kernel = $this->createMock(HttpKernelInterface::class);
$arguments = $resolver->resolve($request, $argument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function provideSupportsData(): iterable
{
yield [
'/login',
Request::create('http://localhost/login', Request::METHOD_POST, [], [], [], [
Request::create('http://localhost/login', 'POST', [], [], [], [
'DOCUMENT_ROOT' => '/var/www/app/public',
'PHP_SELF' => '/index.php',
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
Expand All @@ -44,7 +44,7 @@ public static function provideSupportsData(): iterable
];
yield [
'/login',
Request::create('http://localhost/somepath', Request::METHOD_POST, [], [], [], [
Request::create('http://localhost/somepath', 'POST', [], [], [], [
'DOCUMENT_ROOT' => '/var/www/app/public',
'PHP_SELF' => '/index.php',
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
Expand All @@ -54,7 +54,7 @@ public static function provideSupportsData(): iterable
];
yield [
'/folder/login',
Request::create('http://localhost/folder/login', Request::METHOD_POST, [], [], [], [
Request::create('http://localhost/folder/login', 'POST', [], [], [], [
'DOCUMENT_ROOT' => '/var/www/app/public',
'PHP_SELF' => '/folder/index.php',
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
Expand All @@ -64,7 +64,7 @@ public static function provideSupportsData(): iterable
];
yield [
'/folder/login',
Request::create('http://localhost/folder/somepath', Request::METHOD_POST, [], [], [], [
Request::create('http://localhost/folder/somepath', 'POST', [], [], [], [
'DOCUMENT_ROOT' => '/var/www/app/public',
'PHP_SELF' => '/folder/index.php',
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
Expand All @@ -74,7 +74,7 @@ public static function provideSupportsData(): iterable
];
yield [
'/index.php/login',
Request::create('http://localhost/index.php/login', Request::METHOD_POST, [], [], [], [
Request::create('http://localhost/index.php/login', 'POST', [], [], [], [
'DOCUMENT_ROOT' => '/var/www/app/public',
'PHP_SELF' => '/index.php',
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
Expand All @@ -84,7 +84,7 @@ public static function provideSupportsData(): iterable
];
yield [
'/index.php/login',
Request::create('http://localhost/index.php/somepath', Request::METHOD_POST, [], [], [], [
Request::create('http://localhost/index.php/somepath', 'POST', [], [], [], [
'DOCUMENT_ROOT' => '/var/www/app/public',
'PHP_SELF' => '/index.php',
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testSupport()
$this->setUpAuthenticator();
$request = new Request([], [], [], [], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
$request->request->set('access_token', 'INVALID_ACCESS_TOKEN');
$request->setMethod(Request::METHOD_POST);
$request->setMethod('POST');

$this->assertNull($this->authenticator->supports($request));
}
Expand All @@ -50,7 +50,7 @@ public function testSupportsWithCustomParameter()
$this->setUpAuthenticator('protection-token');
$request = new Request([], [], [], [], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
$request->request->set('protection-token', 'INVALID_ACCESS_TOKEN');
$request->setMethod(Request::METHOD_POST);
$request->setMethod('POST');

$this->assertNull($this->authenticator->supports($request));
}
Expand All @@ -61,7 +61,7 @@ public function testAuthenticate()
$this->setUpAuthenticator();
$request = new Request([], [], [], [], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded'], 'access_token=VALID_ACCESS_TOKEN');
$request->request->set('access_token', 'VALID_ACCESS_TOKEN');
$request->setMethod(Request::METHOD_POST);
$request->setMethod('POST');

$passport = $this->authenticator->authenticate($request);
$this->assertInstanceOf(SelfValidatingPassport::class, $passport);
Expand All @@ -73,7 +73,7 @@ public function testAuthenticateWithCustomParameter()
$this->setUpAuthenticator('protection-token');
$request = new Request([], [], [], [], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
$request->request->set('protection-token', 'VALID_ACCESS_TOKEN');
$request->setMethod(Request::METHOD_POST);
$request->setMethod('POST');

$passport = $this->authenticator->authenticate($request);
$this->assertInstanceOf(SelfValidatingPassport::class, $passport);
Expand All @@ -93,24 +93,24 @@ public function testAuthenticateInvalid(Request $request, string $errorMessage,
public static function provideInvalidAuthenticateData(): iterable
{
$request = new Request();
$request->setMethod(Request::METHOD_GET);
$request->setMethod('GET');
yield [$request, 'Invalid credentials.', BadCredentialsException::class];

$request = new Request();
$request->setMethod(Request::METHOD_POST);
$request->setMethod('POST');
yield [$request, 'Invalid credentials.', BadCredentialsException::class];

$request = new Request([], [], [], [], [], ['HTTP_AUTHORIZATION' => 'Bearer VALID_ACCESS_TOKEN']);
$request->setMethod(Request::METHOD_POST);
$request->setMethod('POST');
yield [$request, 'Invalid credentials.', BadCredentialsException::class];

$request = new Request();
$request->setMethod(Request::METHOD_POST);
$request->setMethod('POST');
$request->request->set('foo', 'VALID_ACCESS_TOKEN');
yield [$request, 'Invalid credentials.', BadCredentialsException::class];

$request = new Request([], [], [], [], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
$request->setMethod(Request::METHOD_POST);
$request->setMethod('POST');
$request->request->set('access_token', 'INVALID_ACCESS_TOKEN');
yield [$request, 'Invalid access token or invalid user.', BadCredentialsException::class];
}
Expand Down
Loading