Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trusted proxies and real ip #564

Open
norkunas opened this issue Feb 15, 2024 · 3 comments
Open

trusted proxies and real ip #564

norkunas opened this issue Feb 15, 2024 · 3 comments
Labels
documentation Documentation needs adjustment enhancement

Comments

@norkunas
Copy link

currently in compose.yaml there is:

TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
TRUSTED_HOSTS: ^${SERVER_NAME:-example\.com|localhost}|php$$

ok so spin up for the localhost, my container has this:

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' www-php-1
172.21.0.1

but for some reason in Symfony $request->getClientIps() returns the container ip. what more configuration is needed?

@dunglas
Copy link
Owner

dunglas commented Feb 15, 2024

We may need to adapt the config to use the new trusted_proxies directive introduced by Caddy: https://caddyserver.com/docs/caddyfile/options#trusted-proxies

@094ikis09
Copy link

It may help you to add the following lines to the file along the config/packages/framework.yaml path:

framework:
    #...any conf
    trusted_headers: [ 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port', 'x-forwarded-prefix' ]
    trusted_proxies: '127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16'
    #...any conf

@norkunas
Copy link
Author

@094ikis09 thanks, tried this on the dev env, but it still returns the docker ip, so I guess I'll have to try caddy trusted_proxies directive.
for the prod env, it works when I list cloudflare ips in trusted proxies, so I get real ip without configuring caddy

@maxhelias maxhelias added the documentation Documentation needs adjustment label Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation needs adjustment enhancement
Projects
None yet
Development

No branches or pull requests

4 participants