Closed andreshg112 closed 6 years ago
getClientIp()
is a Symfony\Component\HttpFoundation\Request
method. Please use their repository.
A quick search turned up this: https://github.com/symfony/symfony/issues/27867
Please close the issue.
I believe this to be the correct behavior. This header is used by proxies, but we have no way of trusting the values. Anyone can set a X-Forwarded-For-header, and the only way we trust those values is if the value comes from a trusted proxy. Even then we can only trust the last value, the one inserted by your trusted proxy. Every other address is a potential lie from a malicious user.
I have the same Issue. I think it is a bug. The header has the format:
X-Forwarded-For:
Sorry about resurrect this issue again. I have two proxies(1 - Cloudflare, 2 - AWS Load Balancer). What would be the best and secure way to retrieve the real client IP in this scenario???
Is there a easy way to retrieve the client real IP from request()->ip()??? For sure i can do a "smart logic" to realize this but is there a "Laravel Way" for do this?
Just an update from anyone that see this thread in the future. I was able to solve the problem setting the "preserve mode" attribute for XFF header in my load balancer. This can be a serious security issue because allow tempering the XFF header then you need to make sure that your load balancer is receiving requests only from the CloudFlare. Just allow only the cloudflare IPS in the LB security group.
Description:
I have logged this in a AWS server.
getOriginalClientIp()
is a custom function.getClientIp
isrequest()->getClientIp()
. You can see it is returning the right-most IP inx-forwarded-for
.getClientIps
isrequest()->getClientIps()
. You can see is sorting inversely IPs that comes from x-forwarded-for.x-forwarded-for
isrequest()->header('x-forwarded-for')
. This is the header received from AWS API Gateway.Custom function:
getClientIp():
app/Http/Middleware/TrustedProxies.php:
I want to use this package https://github.com/antonioribeiro/firewall, but It uses $request->getClientIp(). So I have to make it work in order to use the package.
Steps To Reproduce: