Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3913909
D1638.id4181.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D1638.id4181.diff
View Options
diff --git a/src/HTTP/Requests/RemoteAddress.php b/src/HTTP/Requests/RemoteAddress.php
--- a/src/HTTP/Requests/RemoteAddress.php
+++ b/src/HTTP/Requests/RemoteAddress.php
@@ -31,15 +31,11 @@
}
public function getClientAddress () : string {
- if (strpos($this->remoteAddress, ',') === false) {
- // We only have one value, it's the IP
- return $this->remoteAddress;
- }
-
// Header contains 'clientIP, proxyIP, anotherProxyIP'
+ // or 'clientIP proxyIP anotherProxyIP'
// The first value is so the one to return.
// See draft-ietf-appsawg-http-forwarded-10.
- $ips = explode(',', $this->remoteAddress, 2);
+ $ips = preg_split("/[\s,]+/", $this->remoteAddress, 2);
return trim($ips[0]);
}
diff --git a/tests/HTTP/Requests/RequestTest.php b/tests/HTTP/Requests/RequestTest.php
--- a/tests/HTTP/Requests/RequestTest.php
+++ b/tests/HTTP/Requests/RequestTest.php
@@ -35,6 +35,26 @@
}
/**
+ * @covers \Keruald\OmniTools\HTTP\Requests\Request::getClientAddress
+ * @backupGlobals enabled
+ */
+ public function testGetRemoteAddressWithSeveralAddresses () : void {
+ $_SERVER = [
+ 'HTTP_X_FORWARDED_FOR' => '10.0.0.2 10.0.0.3',
+ ];
+ $this->assertEquals('10.0.0.2', Request::getRemoteAddress(),
+ "HTTP_X_FORWARDED_FOR could contain more than one address, the client one is the first"
+ );
+
+ $_SERVER = [
+ 'HTTP_X_FORWARDED_FOR' => '10.0.0.2, 10.0.0.3',
+ ];
+ $this->assertEquals('10.0.0.2', Request::getRemoteAddress(),
+ "HTTP_X_FORWARDED_FOR could contain more than one address, the client one is the first"
+ );
+ }
+
+ /**
* @covers \Keruald\OmniTools\HTTP\Requests\Request::getAcceptedLanguages
* @backupGlobals enabled
*/
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 12:18 (21 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2307880
Default Alt Text
D1638.id4181.diff (1 KB)
Attached To
Mode
D1638: Improve support for multiple remote addresses
Attached
Detach File
Event Timeline
Log In to Comment