@@ -1775,6 +1775,85 @@ named ``kernel.http_method_override``.
17751775 $request = Request::createFromGlobals();
17761776 // ...
17771777
1778+ .. _configuration-framework-allowed_http_method_override :
1779+
1780+ allowed_http_method_override
1781+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1782+
1783+ .. versionadded :: 7.4
1784+
1785+ The ``allowed_http_method_override `` option was introduced in Symfony 7.4.
1786+
1787+ **type **: ``array `` **default **: ``null ``
1788+
1789+ This option controls which HTTP methods can be overridden via the ``_method ``
1790+ request parameter or the ``X-HTTP-METHOD-OVERRIDE `` header when
1791+ :ref: `http_method_override <configuration-framework-http_method_override >` is enabled.
1792+
1793+ When set to ``null `` (the default), all HTTP methods can be overridden. When set
1794+ to an empty array (``[] ``), HTTP method overriding is completely disabled. When
1795+ set to a specific list of methods, only those methods will be allowed as overrides:
1796+
1797+ .. configuration-block ::
1798+
1799+ .. code-block :: yaml
1800+
1801+ # config/packages/framework.yaml
1802+ framework :
1803+ http_method_override : true
1804+ # Only allow PUT, PATCH, and DELETE to be overridden
1805+ allowed_http_method_override : ['PUT', 'PATCH', 'DELETE']
1806+
1807+ .. code-block :: xml
1808+
1809+ <!-- config/packages/framework.xml -->
1810+ <?xml version =" 1.0" encoding =" UTF-8" ?>
1811+ <container xmlns =" http://symfony.com/schema/dic/services"
1812+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1813+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
1814+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
1815+ https://symfony.com/schema/dic/services/services-1.0.xsd
1816+ http://symfony.com/schema/dic/symfony
1817+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
1818+
1819+ <framework : config http-method-override =" true" >
1820+ <framework : allowed-http-method-override >PUT</framework : allowed-http-method-override >
1821+ <framework : allowed-http-method-override >PATCH</framework : allowed-http-method-override >
1822+ <framework : allowed-http-method-override >DELETE</framework : allowed-http-method-override >
1823+ </framework : config >
1824+ </container >
1825+
1826+ .. code-block :: php
1827+
1828+ // config/packages/framework.php
1829+ use Symfony\Config\FrameworkConfig;
1830+
1831+ return static function (FrameworkConfig $framework): void {
1832+ $framework
1833+ ->httpMethodOverride(true)
1834+ ->allowedHttpMethodOverride(['PUT', 'PATCH', 'DELETE'])
1835+ ;
1836+ };
1837+
1838+ This security feature is useful for hardening your application by explicitly
1839+ defining which methods can be tunneled through POST requests. For example, if
1840+ your application only needs to override POST requests to PUT and DELETE, you
1841+ can restrict the allowed methods accordingly.
1842+
1843+ You can also configure this programmatically using the
1844+ :method: `Request::setAllowedHttpMethodOverride <Symfony\\ Component\\ HttpFoundation\\ Request::setAllowedHttpMethodOverride> `
1845+ method::
1846+
1847+ // public/index.php
1848+
1849+ // ...
1850+ $kernel = new CacheKernel($kernel);
1851+
1852+ Request::enableHttpMethodParameterOverride();
1853+ Request::setAllowedHttpMethodOverride(['PUT', 'PATCH', 'DELETE']);
1854+ $request = Request::createFromGlobals();
1855+ // ...
1856+
17781857.. _reference-framework-ide :
17791858
17801859ide
0 commit comments