File tree Expand file tree Collapse file tree
lib/private/AppFramework/Http
tests/lib/AppFramework/Http Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -659,6 +659,12 @@ public function getRemoteAddress(): string {
659659 if (isset ($ this ->server [$ header ])) {
660660 foreach (explode (', ' , $ this ->server [$ header ]) as $ IP ) {
661661 $ IP = trim ($ IP );
662+
663+ // remove brackets from IPv6 addresses
664+ if (strpos ($ IP , '[ ' ) === 0 && substr ($ IP , -1 ) === '] ' ) {
665+ $ IP = substr ($ IP , 1 , -1 );
666+ }
667+
662668 if (filter_var ($ IP , FILTER_VALIDATE_IP ) !== false ) {
663669 return $ IP ;
664670 }
Original file line number Diff line number Diff line change @@ -634,6 +634,34 @@ public function testGetRemoteAddressWithNotMatchingCidrTrustedRemote() {
634634 $ this ->assertSame ('192.168.3.99 ' , $ request ->getRemoteAddress ());
635635 }
636636
637+ public function testGetRemoteAddressWithXForwardedForIPv6 () {
638+ $ this ->config
639+ ->expects ($ this ->at (0 ))
640+ ->method ('getSystemValue ' )
641+ ->with ('trusted_proxies ' )
642+ ->willReturn (['192.168.2.0/24 ' ]);
643+ $ this ->config
644+ ->expects ($ this ->at (1 ))
645+ ->method ('getSystemValue ' )
646+ ->with ('forwarded_for_headers ' )
647+ ->willReturn (['HTTP_X_FORWARDED_FOR ' ]);
648+
649+ $ request = new Request (
650+ [
651+ 'server ' => [
652+ 'REMOTE_ADDR ' => '192.168.2.99 ' ,
653+ 'HTTP_X_FORWARDED_FOR ' => '[2001:db8:85a3:8d3:1319:8a2e:370:7348] ' ,
654+ ],
655+ ],
656+ $ this ->secureRandom ,
657+ $ this ->config ,
658+ $ this ->csrfTokenManager ,
659+ $ this ->stream
660+ );
661+
662+ $ this ->assertSame ('2001:db8:85a3:8d3:1319:8a2e:370:7348 ' , $ request ->getRemoteAddress ());
663+ }
664+
637665 /**
638666 * @return array
639667 */
You can’t perform that action at this time.
0 commit comments