diff options
author | Joas Schilling <coding@schilljs.com> | 2020-07-02 11:05:02 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2020-07-02 10:09:45 +0000 |
commit | 8cba764b599041fdccf19a91a8ee34de80dea8ba (patch) | |
tree | 4f476002e8a18db68811a8f602634be4bd74bbd5 /tests | |
parent | 2d2b41300a4817412735932efe9292fd59dda764 (diff) | |
download | nextcloud-server-8cba764b599041fdccf19a91a8ee34de80dea8ba.tar.gz nextcloud-server-8cba764b599041fdccf19a91a8ee34de80dea8ba.zip |
Fix IPv6 remote addresses from X_FORWARDED_FOR headers before validating
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/AppFramework/Http/RequestTest.php | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index 56982aaf511..b1542e9d68e 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -634,6 +634,34 @@ class RequestTest extends \Test\TestCase { $this->assertSame('192.168.3.99', $request->getRemoteAddress()); } + public function testGetRemoteAddressWithXForwardedForIPv6() { + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('trusted_proxies') + ->willReturn(['192.168.2.0/24']); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('forwarded_for_headers') + ->willReturn(['HTTP_X_FORWARDED_FOR']); + + $request = new Request( + [ + 'server' => [ + 'REMOTE_ADDR' => '192.168.2.99', + 'HTTP_X_FORWARDED_FOR' => '[2001:db8:85a3:8d3:1319:8a2e:370:7348]', + ], + ], + $this->secureRandom, + $this->config, + $this->csrfTokenManager, + $this->stream + ); + + $this->assertSame('2001:db8:85a3:8d3:1319:8a2e:370:7348', $request->getRemoteAddress()); + } + /** * @return array */ |