2

I'm using the bazinga geocoder in a project on Symfony at work. We use several geolocation part on our application, so we cant use the local ip (127.0.0.1 or our docker IP). We need a fakeIp to work with those geolocation. Moreover we use a proxy in local to get an https connection.

The problem is that when we re-write the ip with our fakeip, symfony consider she can't be trust so we get an error because the re-write don't come from a trusted proxy. Then when we add it to the trustedProxies to tell symfony it's a good ip you can trust her the fakeIp is no more recognize as our IP.

And symfony starts to use my docker IP.I did few researchs on the internet i thought this could be a solution but it only work partially (https://symfony.com/blog/fixing-the-trusted-proxies-configuration-for-symfony-3-3)

Sorry for my english. And i hope you can understand my prb

Here is my code of the fakeRequest listener, and there is no other modification

 /**
 * @var string
 */
protected $fakeIp = null;

public function __construct($fakeIp)
{
    $this->fakeIp = $fakeIp;
}

public function onKernelRequest(GetResponseEvent $event)
{
    if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
        return;
    }

    if (null !== $this->fakeIp && !empty($this->fakeIp)) {
        $event->getRequest()->setTrustedProxies(array($this->fakeIp));
        $event->getRequest()->server->set('REMOTE_ADDR', $this->fakeIp);
    }
}

public function getFakeIp()
{
    return $this->fakeIp;
}
Alex.W
  • 41
  • 4

0 Answers0