Skip to content

Commit

Permalink
removed deprected way to declared trusted proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 23, 2013
1 parent 5ff6006 commit c28f1b0
Show file tree
Hide file tree
Showing 12 changed files with 3 additions and 62 deletions.
Expand Up @@ -56,7 +56,6 @@ public function getConfigTreeBuilder()
->info("Set true to enable support for the '_method' request parameter to determine the intended HTTP method on POST requests.") ->info("Set true to enable support for the '_method' request parameter to determine the intended HTTP method on POST requests.")
->defaultTrue() ->defaultTrue()
->end() ->end()
->scalarNode('trust_proxy_headers')->defaultFalse()->end() // @deprecated, to be removed in 2.3
->arrayNode('trusted_proxies') ->arrayNode('trusted_proxies')
->beforeNormalization() ->beforeNormalization()
->ifTrue(function($v) { return !is_array($v) && !is_null($v); }) ->ifTrue(function($v) { return !is_array($v) && !is_null($v); })
Expand Down
Expand Up @@ -69,10 +69,6 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('kernel.http_method_override', $config['http_method_override']); $container->setParameter('kernel.http_method_override', $config['http_method_override']);


$container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']); $container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']);

// @deprecated, to be removed in 2.3
$container->setParameter('kernel.trust_proxy_headers', $config['trust_proxy_headers']);

$container->setParameter('kernel.default_locale', $config['default_locale']); $container->setParameter('kernel.default_locale', $config['default_locale']);


if (!empty($config['test'])) { if (!empty($config['test'])) {
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Expand Up @@ -43,8 +43,6 @@ public function boot()
{ {
if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) { if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
Request::setTrustedProxies($trustedProxies); Request::setTrustedProxies($trustedProxies);
} elseif ($this->container->getParameter('kernel.trust_proxy_headers')) {
Request::trustProxyData(); // @deprecated, to be removed in 2.3
} }


if ($this->container->getParameter('kernel.http_method_override')) { if ($this->container->getParameter('kernel.http_method_override')) {
Expand Down
Expand Up @@ -25,7 +25,6 @@
<!-- charset is deprecated and will be removed in 2.2 --> <!-- charset is deprecated and will be removed in 2.2 -->
<xsd:attribute name="charset" type="xsd:string" /> <xsd:attribute name="charset" type="xsd:string" />
<xsd:attribute name="http-method-override" type="xsd:boolean" /> <xsd:attribute name="http-method-override" type="xsd:boolean" />
<xsd:attribute name="trust-proxy-headers" type="xsd:string" />
<xsd:attribute name="trusted-proxies" type="xsd:string" /> <xsd:attribute name="trusted-proxies" type="xsd:string" />
<xsd:attribute name="ide" type="xsd:string" /> <xsd:attribute name="ide" type="xsd:string" />
<xsd:attribute name="secret" type="xsd:string" /> <xsd:attribute name="secret" type="xsd:string" />
Expand Down
Expand Up @@ -6,7 +6,7 @@


<parameters> <parameters>
<parameter key="event_dispatcher.class">Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher</parameter> <parameter key="event_dispatcher.class">Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher</parameter>
<parameter key="http_kernel.class">Symfony\Bundle\FrameworkBundle\HttpKernel</parameter> <parameter key="http_kernel.class">Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel</parameter>
<parameter key="filesystem.class">Symfony\Component\Filesystem\Filesystem</parameter> <parameter key="filesystem.class">Symfony\Component\Filesystem\Filesystem</parameter>
<parameter key="cache_warmer.class">Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate</parameter> <parameter key="cache_warmer.class">Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate</parameter>
<parameter key="cache_clearer.class">Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer</parameter> <parameter key="cache_clearer.class">Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer</parameter>
Expand Down
Expand Up @@ -89,7 +89,6 @@ protected static function getBundleDefaultConfig()
return array( return array(
'charset' => null, 'charset' => null,
'http_method_override' => true, 'http_method_override' => true,
'trust_proxy_headers' => false,
'trusted_proxies' => array(), 'trusted_proxies' => array(),
'ide' => null, 'ide' => null,
'default_locale' => 'en', 'default_locale' => 'en',
Expand Down
Expand Up @@ -5,7 +5,6 @@
'default_locale' => 'fr', 'default_locale' => 'fr',
'form' => null, 'form' => null,
'http_method_override' => false, 'http_method_override' => false,
'trust_proxy_headers' => true,
'trusted_proxies' => array('127.0.0.1', '10.0.0.1'), 'trusted_proxies' => array('127.0.0.1', '10.0.0.1'),
'csrf_protection' => array( 'csrf_protection' => array(
'enabled' => true, 'enabled' => true,
Expand Down
Expand Up @@ -6,7 +6,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">


<framework:config secret="s3cr3t" ide="file%%link%%format" default-locale="fr" trust-proxy-headers="true" trusted-proxies="127.0.0.1, 10.0.0.1" http-method-override="false"> <framework:config secret="s3cr3t" ide="file%%link%%format" default-locale="fr" trusted-proxies="127.0.0.1, 10.0.0.1" http-method-override="false">
<framework:csrf-protection enabled="true" field-name="_csrf" /> <framework:csrf-protection enabled="true" field-name="_csrf" />
<framework:form /> <framework:form />
<framework:esi enabled="true" /> <framework:esi enabled="true" />
Expand Down
Expand Up @@ -3,7 +3,6 @@ framework:
default_locale: fr default_locale: fr
form: ~ form: ~
http_method_override: false http_method_override: false
trust_proxy_headers: true
trusted_proxies: ['127.0.0.1', '10.0.0.1'] trusted_proxies: ['127.0.0.1', '10.0.0.1']
csrf_protection: csrf_protection:
enabled: true enabled: true
Expand Down
Expand Up @@ -37,7 +37,6 @@ public function testProxies()
{ {
$container = $this->createContainerFromFile('full'); $container = $this->createContainerFromFile('full');


$this->assertTrue($container->getParameter('kernel.trust_proxy_headers'));
$this->assertEquals(array('127.0.0.1', '10.0.0.1'), $container->getParameter('kernel.trusted_proxies')); $this->assertEquals(array('127.0.0.1', '10.0.0.1'), $container->getParameter('kernel.trusted_proxies'));
} }


Expand Down
25 changes: 0 additions & 25 deletions src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -464,18 +464,6 @@ public function overrideGlobals()
} }
} }


/**
* Trusts $_SERVER entries coming from proxies.
*
* @deprecated Deprecated since version 2.0, to be removed in 2.3. Use setTrustedProxies instead.
*/
public static function trustProxyData()
{
trigger_error('trustProxyData() is deprecated since version 2.0 and will be removed in 2.3. Use setTrustedProxies() instead.', E_USER_DEPRECATED);

self::$trustProxy = true;
}

/** /**
* Sets a list of trusted proxies. * Sets a list of trusted proxies.
* *
Expand Down Expand Up @@ -527,19 +515,6 @@ public static function setTrustedHeaderName($key, $value)
self::$trustedHeaders[$key] = $value; self::$trustedHeaders[$key] = $value;
} }


/**
* Returns true if $_SERVER entries coming from proxies are trusted,
* false otherwise.
*
* @return boolean
*
* @deprecated Deprecated since version 2.2, to be removed in 2.3. Use getTrustedProxies instead.
*/
public static function isProxyTrusted()
{
return self::$trustProxy;
}

/** /**
* Normalizes a query string. * Normalizes a query string.
* *
Expand Down
24 changes: 1 addition & 23 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Expand Up @@ -764,12 +764,7 @@ public function testGetClientIp($expected, $proxy, $remoteAddr, $httpForwardedFo
} }


$request->initialize(array(), array(), array(), array(), array(), $server); $request->initialize(array(), array(), array(), array(), array(), $server);
if ($proxy) { $this->assertEquals($expected, $request->getClientIp());
set_error_handler(array($this, "deprecationErrorHandler"));
$this->startTrustingProxyData();
restore_error_handler();
}
$this->assertEquals($expected, $request->getClientIp($proxy));


Request::setTrustedProxies(array()); Request::setTrustedProxies(array());
} }
Expand Down Expand Up @@ -884,8 +879,6 @@ public function testCreateFromGlobals($method)


public function testOverrideGlobals() public function testOverrideGlobals()
{ {
set_error_handler(array($this, "deprecationErrorHandler"));

$request = new Request(); $request = new Request();
$request->initialize(array('foo' => 'bar')); $request->initialize(array('foo' => 'bar'));


Expand All @@ -903,7 +896,6 @@ public function testOverrideGlobals()


$this->assertArrayNotHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER); $this->assertArrayNotHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER);


$this->startTrustingProxyData();
$request->headers->set('X_FORWARDED_PROTO', 'https'); $request->headers->set('X_FORWARDED_PROTO', 'https');


Request::setTrustedProxies(array('1.1.1.1')); Request::setTrustedProxies(array('1.1.1.1'));
Expand Down Expand Up @@ -1208,11 +1200,6 @@ public function testIsMethod()
$this->assertFalse($request->isMethod('post')); $this->assertFalse($request->isMethod('post'));
} }


private function startTrustingProxyData()
{
Request::trustProxyData();
}

/** /**
* @dataProvider getBaseUrlData * @dataProvider getBaseUrlData
*/ */
Expand Down Expand Up @@ -1342,15 +1329,6 @@ public function testTrustedProxies()
$this->assertEquals(80, $request->getPort()); $this->assertEquals(80, $request->getPort());
$this->assertFalse($request->isSecure()); $this->assertFalse($request->isSecure());


// trusted proxy via deprecated trustProxyData()
set_error_handler(array($this, "deprecationErrorHandler"));
Request::trustProxyData();
$this->assertEquals('2.2.2.2', $request->getClientIp());
$this->assertEquals('real.example.com', $request->getHost());
$this->assertEquals(443, $request->getPort());
$this->assertTrue($request->isSecure());
restore_error_handler();

// disabling proxy trusting // disabling proxy trusting
Request::setTrustedProxies(array()); Request::setTrustedProxies(array());
$this->assertEquals('3.3.3.3', $request->getClientIp()); $this->assertEquals('3.3.3.3', $request->getClientIp());
Expand Down

0 comments on commit c28f1b0

Please sign in to comment.