diff options
author | Joas Schilling <coding@schilljs.com> | 2020-07-02 11:05:02 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-07-02 11:13:13 +0200 |
commit | 74a9cadc501791eaa42b43a7e66eb23a31b2135f (patch) | |
tree | f4c53ee27c0bcc1c668ba77f33e49b184ec79382 /tests | |
parent | ebedbf157968e40230a102c8f6f17c22990b0aae (diff) | |
download | nextcloud-server-74a9cadc501791eaa42b43a7e66eb23a31b2135f.tar.gz nextcloud-server-74a9cadc501791eaa42b43a7e66eb23a31b2135f.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 a8e2f2248c6..7260b31b27e 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -632,6 +632,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 */ |