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
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->info('Sets the list of HTTP methods that can be overridden. Set to null to allow all methods to be overridden (default). Set to an empty array to disallow overrides entirely. Otherwise, provide the list of uppercased method names that are allowed.')
->stringPrototype()->end()
->defaultNull()
->validate()
->ifTrue(static fn ($v) => array_intersect($v, ['GET', 'HEAD', 'CONNECT', 'TRACE']))
->thenInvalid('The HTTP methods "GET", "HEAD", "CONNECT", and "TRACE" cannot be overridden.')
->end()
->end()
->scalarNode('trust_x_sendfile_type_header')
->info('Set true to enable support for xsendfile in binary file responses.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\DBAL\Connection;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
use Symfony\Bundle\FullStack;
Expand Down Expand Up @@ -711,6 +712,25 @@ public function testFormCsrfProtectionFieldAttrDoNotNormalizeKeys()
$this->assertSame(['data-example-attr' => 'value'], $config['form']['csrf_protection']['field_attr'] ?? []);
}

#[TestWith(['CONNECT'])]
#[TestWith(['GET'])]
#[TestWith(['HEAD'])]
#[TestWith(['TRACE'])]
public function testInvalidHttpMethodOverride(string $method)
{
$processor = new Processor();

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The HTTP methods "GET", "HEAD", "CONNECT", and "TRACE" cannot be overridden.');

$processor->processConfiguration(
new Configuration(true),
[[
'allowed_http_method_override' => [$method],
]]
);
}

protected static function getBundleDefaultConfig()
{
return [
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 @@ -698,6 +698,10 @@ public static function getHttpMethodParameterOverride(): bool
*/
public static function setAllowedHttpMethodOverride(?array $methods): void
{
if (array_intersect($methods ?? [], ['GET', 'HEAD', 'CONNECT', 'TRACE'])) {
throw new \InvalidArgumentException('The HTTP methods "GET", "HEAD", "CONNECT", and "TRACE" cannot be overridden.');
}

self::$allowedHttpMethodOverride = $methods;
}

Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ public function testHttpMethodOverrideRespectsAllowedListWithParameter()
}
}

#[TestWith(['CONNECT'])]
#[TestWith(['GET'])]
#[TestWith(['HEAD'])]
#[TestWith(['TRACE'])]
public function testHttpMethodOverrideCannotBeAppliedToCertainMethods(string $httpOverrideMethod)
{
$this->expectException(\InvalidArgumentException::class);

Request::setAllowedHttpMethodOverride([$httpOverrideMethod]);
}

public function testCreateWithRequestUri()
{
$request = Request::create('http://test.com:80/foo');
Expand Down
Loading