Skip to content

ClientConnInfo parsing of dual IPv6 and IPv4 addresses for X-Forwarded-For #3837

Closed

Description

@vsarunas

I did this

When behind nginx reverse proxy, the client IP address does not seem to be parsed correctly if they contain a dual IPv6 and IPv4.

Debug endpoint /v1/debug/ipinfo will show:

 ::ffff:172.17.0.1

If downgrading nginx config to forward to http endpoint instead into a netcat nc -l -p 18443, will see headers like:

GET /ui/login HTTP/1.1
Connection: upgrade
Host: sso.my_domain.com
X-Real-IP: 100.93.168.64
X-Forwarded-For: 100.93.168.64
X-Forwarded-Proto: https
sec-ch-ua: "Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) 

Which is the expected client IP address.

Standard config:

server {
    listen          443 ssl;
    server_name     sso.my_domain.com;
    ssl_certificate sso.cer;
    ssl_certificate_key sso.key;

    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_pass https://10.142.65.1:18443/;
        proxy_ssl_verify off;
    }
}

More about the dual stack: https://www.rfc-editor.org/rfc/rfc4291.html#section-2.2

server.toml does have the trust of the header:

[http_client_address_info]
x-forward-for = ["127.0.0.1", "127.0.0.0/8", "172.16.0.0/12", "172.17.0.1/32" ]

I expected the following

I expect client_address log entry to show IP of X-Forwarded-For.

It only works if setting:

x-forward-for = ["127.0.0.1", "127.0.0.0/8",  "::ffff:172.17.0.1" ]

A range will fail with ::ffff:172.17.0.0/12

With:

host part of address was not zero

Is this a problem of https://github.com/stbuehler/rust-cidr ?

This happened instead

Ignore the IPv6 and accept IPv4 address that is in the whitelist.

Kanidm version details

docker container v1.7.3

Any other comments

Activity

  1. Firstyear commented on Sep 4, 2025

    @Firstyear
    Member
  2. Firstyear commented on Sep 4, 2025

    @Firstyear
    Member

    And yes if you want subnetting support to work on those mapped addresses that would be a bug for rust-cidr.

  3. Blacks-Army commented on Sep 8, 2025

    @Blacks-Army

    When subnetting your IPv4 range in IPv6 notation, you also need to set the CIDR to the IPv6 equivalent. See here:

    x-forward-for = ["::ffff:172.20.27.0/120"]
    

    This works for me.

    Also, @Firstyear, maybe this should be documented in the example TOML, because the IPv4 examples there aren’t correct and do not work.

  4. vkukk commented on Sep 30, 2025

    @vkukk

    I've hit the same issue on GKE.

    This works for external load balancers:

    x-forward-for = ["::ffff:35.191.0.0/112"]
    
  5. Blacks-Army commented on Sep 30, 2025

    @Blacks-Army

    @Firstyear I believe this can be closed, as it’s not really an issue but rather a gap in the documentation.

  6. self-assigned this
    on Sep 30, 2025
  7. moved this from 🆕 New to ✅ Done in Organising Everythingon Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions