mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
fix(request): Handle reverse proxy setting a port in Forwarded-For
Signed-off-by: Mikael Peigney <Mika56@users.noreply.github.com>
This commit is contained in:
parent
8822b16d37
commit
ffcadf25d4
1 changed files with 10 additions and 4 deletions
|
|
@ -607,10 +607,16 @@ class Request implements \ArrayAccess, \Countable, IRequest {
|
|||
if (isset($this->server[$header])) {
|
||||
foreach (array_reverse(explode(',', $this->server[$header])) as $IP) {
|
||||
$IP = trim($IP);
|
||||
|
||||
// remove brackets from IPv6 addresses
|
||||
if (str_starts_with($IP, '[') && str_ends_with($IP, ']')) {
|
||||
$IP = substr($IP, 1, -1);
|
||||
$colons = substr_count($IP, ':');
|
||||
if($colons > 1) {
|
||||
// Extract IP from string with brackets and optional port
|
||||
if(1 === preg_match('`^\[(.+?)\](?::\d+)?$`', $IP, $matches) && count($matches) === 1) {
|
||||
$IP = $matches[0];
|
||||
}
|
||||
}
|
||||
elseif($colons === 1) {
|
||||
// IPv4 with port
|
||||
$IP = substr($IP, 0, strpos($IP, ':'));
|
||||
}
|
||||
|
||||
if ($this->isTrustedProxy($trustedProxies, $IP)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue