Validate IP header

This commit is contained in:
Marius Karstedt
2021-03-22 11:15:47 +01:00
parent 90a0ca2ee8
commit 24f7e3ab13
+8 -7
View File
@@ -165,17 +165,18 @@ class Request
*/ */
public function getIp(bool $safe = false): ?string public function getIp(bool $safe = false): ?string
{ {
$client_header = null;
if(!$safe){ if(!$safe){
if ($this->getHeader('http-cf-connecting-ip') !== null) { if ($this->getHeader('http-cf-connecting-ip') !== null) {
return $this->getHeader('http-cf-connecting-ip'); $client_header = $this->getHeader('http-cf-connecting-ip');
} }else if($this->getHeader('http-client-ip') !== null){
if($this->getHeader('http-client-ip') !== null){ $client_header = $this->getHeader('http-client-ip');
return $this->getHeader('http-client-ip'); }else if($this->getHeader('http-x-forwarded-for') !== null){
} $client_header = $this->getHeader('http-x-forwarded-for');
if($this->getHeader('http-x-forwarded-for') !== null){
return $this->getHeader('http-x-forwarded-for');
} }
} }
if($client_header !== null && filter_var($client_header, FILTER_VALIDATE_IP))
return $client_header;
return $this->getHeader('remote-addr'); return $this->getHeader('remote-addr');
} }