Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 83fc742

Browse filesBrowse files
committed
feature #22238 [BC BREAK][HttpFoundation] Request::setTrustedProxies() takes a new required $trustedHeaderSet argument (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [BC BREAK][HttpFoundation] Request::setTrustedProxies() takes a new required $trustedHeaderSet argument | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | yes | BC breaks? | yes | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #20178 | License | MIT | Doc PR | - As discussed in linked issue, and already deprecated by #21830 Commits ------- 72e2895 [BC BREAK][HttpFoundation] Request::setTrustedProxies() takes a new required $trustedHeaderSet argument
2 parents 0d85a99 + 72e2895 commit 83fc742
Copy full SHA for 83fc742

File tree

10 files changed

+15
-129
lines changed
Filter options

10 files changed

+15
-129
lines changed

‎UPGRADE-3.3.md

Copy file name to clipboardExpand all lines: UPGRADE-3.3.md
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ FrameworkBundle
207207
HttpFoundation
208208
--------------
209209

210-
* The `Request::setTrustedProxies()` method takes a new `$trustedHeaderSet` argument - not setting it is deprecated.
211-
Set it to `Request::HEADER_FORWARDED` if your reverse-proxy uses the RFC7239 `Forwarded` header,
212-
or to `Request::HEADER_X_FORWARDED_ALL` if it is using `X-Forwarded-*` headers instead.
210+
* [BC BREAK] The `Request::setTrustedProxies()` method takes a new `$trustedHeaderSet` argument.
211+
See http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html for more info.
213212

214213
* The `Request::setTrustedHeaderName()` and `Request::getTrustedHeaderName()` methods are deprecated,
215214
use the RFC7239 `Forwarded` header, or the `X-Forwarded-*` headers instead.

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ HttpFoundation
300300
--------------
301301

302302
* The `Request::setTrustedProxies()` method takes a new `$trustedHeaderSet` argument.
303-
Set it to `Request::HEADER_FORWARDED` if your reverse-proxy uses the RFC7239 `Forwarded` header,
304-
or to `Request::HEADER_X_FORWARDED_ALL` if it is using `X-Forwarded-*` headers instead.
303+
See http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html for more info.
305304

306305
* The `Request::setTrustedHeaderName()` and `Request::getTrustedHeaderName()` methods have been removed.
307306

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ CHANGELOG
44
3.3.0
55
-----
66

7+
* [BC BREAK] Removed the "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter
78
* Added a new new version strategy option called json_manifest_path
89
that allows you to use the `JsonManifestVersionStrategy`.
910
* Added `Symfony\Bundle\FrameworkBundle\Controller\AbstractController`. It provides
1011
the same helpers as the `Controller` class, but does not allow accessing the dependency
1112
injection container, in order to encourage explicit dependency declarations.
1213
* Added support for the `controller.service_arguments` tag, for injecting services into controllers' actions
1314
* Deprecated `cache:clear` with warmup (always call it with `--no-warmup`)
14-
* Deprecated the "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter
1515
* Changed default configuration for
1616
assets/forms/validation/translation/serialization/csrf from `canBeEnabled()` to
1717
`canBeDisabled()` when Flex is used

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+3-35Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -59,48 +59,16 @@ public function getConfigTreeBuilder()
5959
return $v;
6060
})
6161
->end()
62-
->beforeNormalization()
63-
->ifTrue(function ($v) { return isset($v['trusted_proxies']); })
64-
->then(function ($v) {
65-
@trigger_error('The "framework.trusted_proxies" configuration key is deprecated since version 3.3 and will be removed in 4.0. Use the Request::setTrustedProxies() method in your front controller instead.', E_USER_DEPRECATED);
66-
67-
return $v;
68-
})
69-
->end()
7062
->children()
7163
->scalarNode('secret')->end()
7264
->scalarNode('http_method_override')
7365
->info("Set true to enable support for the '_method' request parameter to determine the intended HTTP method on POST requests. Note: When using the HttpCache, you need to call the method in your front controller instead")
7466
->defaultTrue()
7567
->end()
76-
->arrayNode('trusted_proxies')
68+
->arrayNode('trusted_proxies') // @deprecated in version 3.3, to be removed in 4.0
7769
->beforeNormalization()
78-
->ifTrue(function ($v) { return !is_array($v) && null !== $v; })
79-
->then(function ($v) { return is_bool($v) ? array() : preg_split('/\s*,\s*/', $v); })
80-
->end()
81-
->prototype('scalar')
82-
->validate()
83-
->ifTrue(function ($v) {
84-
if (empty($v)) {
85-
return false;
86-
}
87-
88-
if (false !== strpos($v, '/')) {
89-
if ('0.0.0.0/0' === $v) {
90-
return false;
91-
}
92-
93-
list($v, $mask) = explode('/', $v, 2);
94-
95-
if (strcmp($mask, (int) $mask) || $mask < 1 || $mask > (false !== strpos($v, ':') ? 128 : 32)) {
96-
return true;
97-
}
98-
}
99-
100-
return !filter_var($v, FILTER_VALIDATE_IP);
101-
})
102-
->thenInvalid('Invalid proxy IP "%s"')
103-
->end()
70+
->always()
71+
->thenInvalid('The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.')
10472
->end()
10573
->end()
10674
->scalarNode('ide')->defaultNull()->end()

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public function load(array $configs, ContainerBuilder $container)
124124

125125
$container->setParameter('kernel.http_method_override', $config['http_method_override']);
126126
$container->setParameter('kernel.trusted_hosts', $config['trusted_hosts']);
127-
$container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']);
128127
$container->setParameter('kernel.default_locale', $config['default_locale']);
129128

130129
if (!$container->hasParameter('debug.file_link_format')) {

‎src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ public function boot()
6161
{
6262
ErrorHandler::register(null, false)->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true);
6363

64-
if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
64+
if ($this->container->hasParameter('kernel.trusted_proxies')) {
6565
@trigger_error('The "kernel.trusted_proxies" parameter is deprecated since version 3.3 and will be removed in 4.0. Use the Request::setTrustedProxies() method in your front controller instead.', E_USER_DEPRECATED);
6666

67-
Request::setTrustedProxies($trustedProxies, Request::getTrustedHeaderSet());
67+
if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
68+
Request::setTrustedProxies($trustedProxies, Request::getTrustedHeaderSet());
69+
}
6870
}
6971

7072
if ($this->container->getParameter('kernel.http_method_override')) {

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
-65Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -43,70 +43,6 @@ public function testDoNoDuplicateDefaultFormResources()
4343
$this->assertEquals(array('FrameworkBundle:Form'), $config['templating']['form']['resources']);
4444
}
4545

46-
/**
47-
* @group legacy
48-
* @dataProvider getTestValidTrustedProxiesData
49-
*/
50-
public function testValidTrustedProxies($trustedProxies, $processedProxies)
51-
{
52-
$processor = new Processor();
53-
$configuration = new Configuration(true);
54-
$config = $processor->processConfiguration($configuration, array(array(
55-
'secret' => 's3cr3t',
56-
'trusted_proxies' => $trustedProxies,
57-
)));
58-
59-
$this->assertEquals($processedProxies, $config['trusted_proxies']);
60-
}
61-
62-
public function getTestValidTrustedProxiesData()
63-
{
64-
return array(
65-
array(array('127.0.0.1'), array('127.0.0.1')),
66-
array(array('::1'), array('::1')),
67-
array(array('127.0.0.1', '::1'), array('127.0.0.1', '::1')),
68-
array(null, array()),
69-
array(false, array()),
70-
array(array(), array()),
71-
array(array('10.0.0.0/8'), array('10.0.0.0/8')),
72-
array(array('::ffff:0:0/96'), array('::ffff:0:0/96')),
73-
array(array('0.0.0.0/0'), array('0.0.0.0/0')),
74-
);
75-
}
76-
77-
/**
78-
* @group legacy
79-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
80-
*/
81-
public function testInvalidTypeTrustedProxies()
82-
{
83-
$processor = new Processor();
84-
$configuration = new Configuration(true);
85-
$processor->processConfiguration($configuration, array(
86-
array(
87-
'secret' => 's3cr3t',
88-
'trusted_proxies' => 'Not an IP address',
89-
),
90-
));
91-
}
92-
93-
/**
94-
* @group legacy
95-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
96-
*/
97-
public function testInvalidValueTrustedProxies()
98-
{
99-
$processor = new Processor();
100-
$configuration = new Configuration(true);
101-
102-
$processor->processConfiguration($configuration, array(
103-
array(
104-
'secret' => 's3cr3t',
105-
'trusted_proxies' => array('Not an IP address'),
106-
),
107-
));
108-
}
109-
11046
public function testAssetsCanBeEnabled()
11147
{
11248
$processor = new Processor();
@@ -188,7 +124,6 @@ protected static function getBundleDefaultConfig()
188124
{
189125
return array(
190126
'http_method_override' => true,
191-
'trusted_proxies' => array(),
192127
'ide' => null,
193128
'default_locale' => 'en',
194129
'csrf_protection' => array(

‎src/Symfony/Component/HttpFoundation/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/CHANGELOG.md
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ CHANGELOG
44
3.3.0
55
-----
66

7-
* added `$trustedHeaderSet` argument to `Request::setTrustedProxies()` - deprecate not setting it,
7+
* [BC BREAK] the `Request::setTrustedProxies()` method takes a new `$trustedHeaderSet` argument,
8+
see http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html for more info,
89
* deprecated the `Request::setTrustedHeaderName()` and `Request::getTrustedHeaderName()` methods,
910
* added `File\Stream`, to be passed to `BinaryFileResponse` when the size of the served file is unknown,
1011
disabling `Range` and `Content-Length` handling, switching to chunked encoding instead

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,8 @@ public static function setTrustedProxies(array $proxies/*, int $trustedHeaderSet
589589
self::$trustedProxies = $proxies;
590590

591591
if (2 > func_num_args()) {
592-
@trigger_error(sprintf('The %s() method expects a bit field of Request::HEADER_* as second argument. Not defining it is deprecated since version 3.3 and will be required in 4.0.', __METHOD__), E_USER_DEPRECATED);
593-
594-
return;
592+
// @deprecated code path in 3.3, to be replaced by mandatory argument in 4.0.
593+
throw new \InvalidArgumentException(sprintf('The %s() method expects a bit field of Request::HEADER_* as second argument. Defining it is required since version 3.3. See http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html for more info.', __METHOD__));
595594
}
596595
$trustedHeaderSet = func_get_arg(1);
597596

‎src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
-16Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,22 +2125,6 @@ public function methodCacheableProvider()
21252125
);
21262126
}
21272127

2128-
/**
2129-
* @group legacy
2130-
* @expectedDeprecation The Symfony\Component\HttpFoundation\Request::setTrustedProxies() method expects a bit field of Request::HEADER_* as second argument. Not defining it is deprecated since version 3.3 and will be required in 4.0.
2131-
* @expectedDeprecation The "Symfony\Component\HttpFoundation\Request::getTrustedHeaderName()" method is deprecated since version 3.3 and will be removed in 4.0. Use the Request::getTrustedHeaderSet() method instead.
2132-
*/
2133-
public function testSetTrustedProxiesNoSecondArg()
2134-
{
2135-
Request::setTrustedProxies(array('8.8.8.8'));
2136-
2137-
$this->assertSame('FORWARDED', Request::getTrustedHeaderName(Request::HEADER_FORWARDED));
2138-
$this->assertSame('X_FORWARDED_FOR', Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP));
2139-
$this->assertSame('X_FORWARDED_HOST', Request::getTrustedHeaderName(Request::HEADER_CLIENT_HOST));
2140-
$this->assertSame('X_FORWARDED_PORT', Request::getTrustedHeaderName(Request::HEADER_CLIENT_PORT));
2141-
$this->assertSame('X_FORWARDED_PROTO', Request::getTrustedHeaderName(Request::HEADER_CLIENT_PROTO));
2142-
}
2143-
21442128
/**
21452129
* @group legacy
21462130
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.