Symfony allows direct access of ESI URLs behind a trusted proxy
Description
All 2.2.X, 2.3.X, 2.4.X, and 2.5.X versions of the Symfony HttpKernel component are affected by this security issue. Your application is vulnerable only if the ESI feature is enabled and there is a proxy in front of the web application.
This issue has been fixed in Symfony 2.3.19, 2.4.9, and 2.5.4. Note that no fixes are provided for Symfony 2.2 as it is not maintained anymore.
Description When you enable the ESI feature and when you are using a proxy like Varnish that you configured as a trusted proxy, the FragmentHandler considered requests to render fragments as coming from a trusted source, even if the client was requesting them directly. Symfony can not distinguish between ESI requests done on behalf of the client by Varnish and faked fragment requests coming directly from the client.
To mitigate this issue, and for not-supported Symfony versions, you can use the following workaround in your Varnish configuration (/_fragment being the URL path prefix configured under the fragment setting of the framework bundle configuration):
Copy sub vcl_recv { if (req.restarts == 0 && req.url ~ "^/_fragment") { error 400; } } Resolution We do not rely on trusted IPs anymore when validating a fragment request as all fragment URLs are now signed.
The patch for this issue is available here: https://github.com/symfony/symfony/pull/11831
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
symfony/http-kernelPackagist | >= 2.0.0, < 2.3.19 | 2.3.19 |
symfony/http-kernelPackagist | >= 2.4.0, < 2.4.9 | 2.4.9 |
symfony/http-kernelPackagist | >= 2.5.0, < 2.5.4 | 2.5.4 |
symfony/symfonyPackagist | >= 2.0.0, < 2.3.19 | 2.3.19 |
symfony/symfonyPackagist | >= 2.4.0, < 2.4.9 | 2.4.9 |
symfony/symfonyPackagist | >= 2.5.0, < 2.5.4 | 2.5.4 |
Patches
1654b1f281e09Forced all fragment uris to be signed, even for ESI
5 files changed · +72 −25
src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml+1 −0 modified@@ -22,6 +22,7 @@ <tag name="kernel.fragment_renderer" /> <argument type="service" id="esi" /> <argument type="service" id="fragment.renderer.inline" /> + <argument type="service" id="uri_signer" /> <call method="setFragmentPath"><argument>%fragment.path%</argument></call> </service> </services>
src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php+5 −8 modified@@ -12,7 +12,6 @@ namespace Symfony\Component\HttpKernel\EventListener; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\IpUtils; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -77,13 +76,6 @@ protected function validateRequest(Request $request) throw new AccessDeniedHttpException(); } - // does the Request come from a trusted IP? - $trustedIps = array_merge($this->getLocalIpAddresses(), $request->getTrustedProxies()); - $remoteAddress = $request->server->get('REMOTE_ADDR'); - if (IpUtils::checkIp($remoteAddress, $trustedIps)) { - return; - } - // is the Request signed? // we cannot use $request->getUri() here as we want to work with the original URI (no query string reordering) if ($this->signer->check($request->getSchemeAndHttpHost().$request->getBaseUrl().$request->getPathInfo().(null !== ($qs = $request->server->get('QUERY_STRING')) ? '?'.$qs : ''))) { @@ -93,6 +85,11 @@ protected function validateRequest(Request $request) throw new AccessDeniedHttpException(); } + /** + * @deprecated Deprecated since 2.3.19, to be removed in 3.0. + * + * @return string[] + */ protected function getLocalIpAddresses() { return array('127.0.0.1', 'fe80::1', '::1');
src/Symfony/Component/HttpKernel/Fragment/EsiFragmentRenderer.php+19 −3 modified@@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\HttpCache\Esi; +use Symfony\Component\HttpKernel\UriSigner; /** * Implements the ESI rendering strategy. @@ -25,6 +26,7 @@ class EsiFragmentRenderer extends RoutableFragmentRenderer { private $esi; private $inlineStrategy; + private $signer; /** * Constructor. @@ -34,11 +36,13 @@ class EsiFragmentRenderer extends RoutableFragmentRenderer * * @param Esi $esi An Esi instance * @param FragmentRendererInterface $inlineStrategy The inline strategy to use when ESI is not supported + * @param UriSigner $signer */ - public function __construct(Esi $esi, FragmentRendererInterface $inlineStrategy) + public function __construct(Esi $esi, FragmentRendererInterface $inlineStrategy, UriSigner $signer = null) { $this->esi = $esi; $this->inlineStrategy = $inlineStrategy; + $this->signer = $signer; } /** @@ -61,12 +65,12 @@ public function render($uri, Request $request, array $options = array()) } if ($uri instanceof ControllerReference) { - $uri = $this->generateFragmentUri($uri, $request); + $uri = $this->generateSignedFragmentUri($uri, $request); } $alt = isset($options['alt']) ? $options['alt'] : null; if ($alt instanceof ControllerReference) { - $alt = $this->generateFragmentUri($alt, $request); + $alt = $this->generateSignedFragmentUri($alt, $request); } $tag = $this->esi->renderIncludeTag($uri, $alt, isset($options['ignore_errors']) ? $options['ignore_errors'] : false, isset($options['comment']) ? $options['comment'] : ''); @@ -81,4 +85,16 @@ public function getName() { return 'esi'; } + + private function generateSignedFragmentUri($uri, Request $request) + { + if (null === $this->signer) { + throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.'); + } + + // we need to sign the absolute URI, but want to return the path only. + $fragmentUri = $this->signer->sign($this->generateFragmentUri($uri, $request, true)); + + return substr($fragmentUri, strlen($request->getSchemeAndHttpHost())); + } }
src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php+0 −13 modified@@ -54,19 +54,6 @@ public function testAccessDeniedWithNonSafeMethods() $listener->onKernelRequest($event); } - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException - */ - public function testAccessDeniedWithNonLocalIps() - { - $request = Request::create('http://example.com/_fragment', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); - - $listener = new FragmentListener(new UriSigner('foo')); - $event = $this->createGetResponseEvent($request); - - $listener->onKernelRequest($event); - } - /** * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */
src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php+47 −1 modified@@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer; use Symfony\Component\HttpKernel\HttpCache\Esi; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\UriSigner; class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase { @@ -48,7 +49,52 @@ public function testRender() $this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent()); $this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent()); $this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent()); - $this->assertEquals('<esi:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller" />', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent()); + } + + public function testRenderControllerReference() + { + $signer = new UriSigner('foo'); + $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(), $signer); + + $request = Request::create('/'); + $request->setLocale('fr'); + $request->headers->set('Surrogate-Capability', 'ESI/1.0'); + + $reference = new ControllerReference('main_controller', array(), array()); + $altReference = new ControllerReference('alt_controller', array(), array()); + + $this->assertEquals( + '<esi:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller&_hash=wDaFy1WsZUOWrrMdRMgJ1cOskFo%3D" alt="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller&_hash=56ycnRUlgaremRQVStZsGbVhIv8%3D" />', + $strategy->render($reference, $request, array('alt' => $altReference))->getContent() + ); + } + + /** + * @expectedException \LogicException + */ + public function testRenderControllerReferenceWithoutSignerThrowsException() + { + $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy()); + + $request = Request::create('/'); + $request->setLocale('fr'); + $request->headers->set('Surrogate-Capability', 'ESI/1.0'); + + $strategy->render(new ControllerReference('main_controller'), $request); + } + + /** + * @expectedException \LogicException + */ + public function testRenderAltControllerReferenceWithoutSignerThrowsException() + { + $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy()); + + $request = Request::create('/'); + $request->setLocale('fr'); + $request->headers->set('Surrogate-Capability', 'ESI/1.0'); + + $strategy->render('/', $request, array('alt' => new ControllerReference('alt_controller'))); } private function getInlineStrategy($called = false)
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
6- github.com/advisories/GHSA-wvjv-p5rr-mmqmghsaADVISORY
- github.com/FriendsOfPHP/security-advisories/blob/master/symfony/http-kernel/CVE-2014-5245.yamlghsaWEB
- github.com/FriendsOfPHP/security-advisories/blob/master/symfony/symfony/CVE-2014-5245.yamlghsaWEB
- github.com/symfony/symfony/commit/654b1f281e09dd96ffbbd3da815411700423ecf5ghsaWEB
- github.com/symfony/symfony/pull/11831ghsaWEB
- symfony.com/cve-2014-5245ghsaWEB
News mentions
0No linked articles in our index yet.