Skip to content

Commit ad15ae1

Browse files
authored
Merge pull request #2526 from acelaya-forks/remove-trusted-proxies-workaround
Remove workaround to detect trusted proxies automatically
2 parents 8a33c69 + a731e01 commit ad15ae1

File tree

5 files changed

+3
-133
lines changed

5 files changed

+3
-133
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
99
* *Nothing*
1010

1111
### Changed
12-
* *Nothing*
12+
* [#2522](https://github.com/shlinkio/shlink/issues/2522) Shlink no longer tries to detect trusted proxies automatically, when resolving the visitor's IP address, as this is a potential security issue.
13+
14+
Instead, if you have more than 1 proxy in front of Shlink, you should provide `TRUSTED_PROXIES` env var, with either a comma-separated list of the IP addresses of your proxies, or a number indicating how many proxies are there in front of Shlink.
1315

1416
### Deprecated
1517
* *Nothing*

config/autoload/ip-address.global.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use RKA\Middleware\IpAddress;
66
use RKA\Middleware\Mezzio\IpAddressFactory;
77
use Shlinkio\Shlink\Core\Config\EnvVars;
8-
use Shlinkio\Shlink\Core\Middleware\ReverseForwardedAddressesMiddlewareDecorator;
98

109
use function Shlinkio\Shlink\Core\splitByComma;
1110

@@ -43,18 +42,6 @@
4342
'factories' => [
4443
IpAddress::class => IpAddressFactory::class,
4544
],
46-
'delegators' => [
47-
// Make middleware decoration transparent to other parts of the code
48-
IpAddress::class => [
49-
fn ($c, $n, callable $callback) =>
50-
// If trusted proxies have been provided, use original middleware verbatim, otherwise decorate
51-
// with workaround
52-
$trustedProxies !== null
53-
? $callback()
54-
: new ReverseForwardedAddressesMiddlewareDecorator($callback()),
55-
],
56-
],
57-
5845
],
5946

6047
];

module/Core/src/Middleware/ReverseForwardedAddressesMiddlewareDecorator.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

module/Core/test-api/Action/RedirectTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,6 @@ public static function provideRequestOptions(): iterable
106106
'https://example.com/static-ip-address',
107107
];
108108
}
109-
110-
yield 'rule: IP address in "X-Forwarded-For" together with proxy addresses' => [
111-
[
112-
RequestOptions::HEADERS => [
113-
'X-Forwarded-For' => '1.2.3.4, 192.168.1.1, 192.168.1.2',
114-
],
115-
],
116-
'https://example.com/static-ip-address',
117-
];
118109
}
119110

120111
/**

module/Core/test/Middleware/ReverseForwardedAddressesMiddlewareDecoratorTest.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)