Thanks to visit codestin.com
Credit goes to github.com

Skip to content

get a SecureIp with bazinga geocoder #129

Closed
@blade503

Description

@blade503

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

The problem is that when I re-write the ip with my fakeip, symfony consider she can't be trust so I get an error because the re-write don't come from my local trusted proxy. Then when I add the IP in the trustedProxies to tell symfony it's a good ip and that he can trust her, but the fakeIp is no more recognize as my local 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). I tried to add the trusted proxy of the FakeIP on the FakeRequestListener. But i don't get the result i'm looking for

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

Here is where I am at the moment, it works but i'm forced to add the fakeip in the trusted proxies, thing that i don't want to do, so how could I avoid that ? I just want to reproduce the behaviour of the app on prod, but in local =)

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

    if (null !== $this->fakeIp && !empty($this->fakeIp)) {
           $event->getRequest()->server->set('REMOTE_ADDR', $this->fakeIp);
            $event->getRequest()->setTrustedProxies(array($this->fakeIp));
            $res = $event->getRequest()->getTrustedHeaderName(Request::HEADER_CLIENT_IP);
            $event->getRequest()->setTrustedHeaderName(Request::HEADER_CLIENT_IP , $this->fakeIp  .','. $res );
        }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions