Skip to content

Commit 5b0d25c

Browse files
committed
add a private_ranges shortcut for trusted_proxies
1 parent c71348a commit 5b0d25c

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Add `private_ranges` as a shortcut for private IP address ranges to the `trusted_proxies` option
8+
49
7.0
510
---
611

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ public function getConfigTreeBuilder(): TreeBuilder
111111
->beforeNormalization()->ifString()->then(fn ($v) => [$v])->end()
112112
->prototype('scalar')->end()
113113
->end()
114-
->scalarNode('trusted_proxies')->end()
114+
->scalarNode('trusted_proxies')
115+
->beforeNormalization()
116+
->ifTrue(fn ($v) => 'private_ranges' === $v)
117+
->then(fn ($v) => '192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8, 127.0.0.1/8, fd00::/8, ::1')
118+
->end()
119+
->end()
115120
->arrayNode('trusted_headers')
116121
->fixXmlConfig('trusted_header')
117122
->performNoDeepMerging()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'trusted_proxies' => 'private_ranges',
5+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config trusted-proxies="private_ranges" />
9+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
framework:
2+
trusted_proxies: private_ranges

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

+7
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,13 @@ public function testNotifierWithSpecificMessageBus()
22642264
$this->assertEquals(new Reference('app.another_bus'), $container->getDefinition('notifier.channel.sms')->getArgument(1));
22652265
}
22662266

2267+
public function testTrustedProxiesWithPrivateRanges()
2268+
{
2269+
$container = $this->createContainerFromFile('trusted_proxies_private_ranges');
2270+
2271+
$this->assertSame('192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8, 127.0.0.1/8, fd00::/8, ::1', $container->getParameter('kernel.trusted_proxies'));
2272+
}
2273+
22672274
public function testWebhook()
22682275
{
22692276
if (!class_exists(WebhookController::class)) {

0 commit comments

Comments
 (0)