Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

IP Returned Incorrectly #5

Open
droans opened this issue Sep 21, 2021 · 9 comments
Open

IP Returned Incorrectly #5

droans opened this issue Sep 21, 2021 · 9 comments

Comments

@droans
Copy link

droans commented Sep 21, 2021

Plugin returns IP as ", 123.123.123.123" instead of just "123.123.123.123"

Configuration:

Docker

traefik:
  container_name: traefik
  image: traefik:brie
  restart: unless-stopped
  command:
     - --experimental.plugins.traefik-real-ip.modulename=github.com/soulbalz/traefik-real-ip
     - --experimental.plugins.traefik-real-ip.version=v1.0.3

middlewares.toml:

[http.middlewares.my-traefik-real-ip]
  [http.middlewares.my-traefik-real-ip.plugin]
    [http.middlewares.my-traefik-real-ip.plugin.traefik-real-ip]
      excludednets = ["192.168.86.0/24", "10.10.0.0/16","172.0.0.0/8"]

Test:

Home Assistant: Invalid IP address in X-Forwarded For: , 192.168.XX.XX

Whats My IP Container result: , 192.168.XX.XX

Same issue with setting excludednets equal to 0.0.0.0/32, 0.0.0.0/0, or any of the individual options above. Seems to work fine for any external IP addresses, just internal causes issues.

@yfhyou
Copy link

yfhyou commented Feb 1, 2022

As it shows in the description, this plugin writes the X-Real-Ip header, not the 'x-forwarded-for' header.
You should check the x-real-ip result instead when using this plugin.

This plugin solves this issue by overwriting the X-Real-Ip with an IP from the X-Forwarded-For or Cf-Connecting-Ip (if from Cloudflare) header.

@droans
Copy link
Author

droans commented Feb 2, 2022

As it shows in the description, this plugin writes the X-Real-Ip header, not the 'x-forwarded-for' header. You should check the x-real-ip result instead when using this plugin.

This plugin solves this issue by overwriting the X-Real-Ip with an IP from the X-Forwarded-For or Cf-Connecting-Ip (if from Cloudflare) header.

req.Header.Set(xForwardedFor, realIP)

The plugin also sets the X-Forwarded-For based on the Cf-Connecting-Ip if X-Real-IP can't be pulled from X-Forwarded-For.

@yfhyou
Copy link

yfhyou commented Feb 8, 2022

I see what you mean. I set up a test that didn't include cf-connection-ip and I get a similar result
, 1.2.3.4

@simon-sudo
Copy link

same here, I used another plugin and it worked well

https://github.com/Paxxs/traefik-get-real-ip

@bverwijst
Copy link

@simon-sudo mind if I ask you how you configured Cloudflare? I'm struggling with configuring the rule expression in the Cloudflare rule to rewrite the header. I have the same issue with just Home Assistant, I'm having the same result with the extra , like the results above.

@simon-sudo
Copy link

@bverwijst

add this plugin to the configuration file:

experimental:
  plugins:
    real-ip:
      moduleName: github.com/Paxxs/traefik-get-real-ip
      version: [Please fill the latest version !]

set two values like this:

  • X-From-Cdn
  • cf-my
http:
  middlewares:
    real-ip-foo:
      plugin:
        real-ip:
          Proxy:
            - proxyHeadername: X-From-Cdn
              proxyHeadervalue: cf-my
              realIP: Cf-Connecting-Ip
              OverwriteXFF: true
            - proxyHeadername: "*"
              realIP: RemoteAddr

image

image

image

Reference : https://github.com/Paxxs/traefik-get-real-ip#cdn-configuration

@bverwijst
Copy link

@simon-sudo Brilliant, the expression was all I wanted to know, the rest I had correct. Much much appreciated, working like a charm now!

@joggs
Copy link

joggs commented Aug 11, 2022

Plugin returns IP as ", 123.123.123.123" instead of just "123.123.123.123"

Configuration:

Docker

traefik:
  container_name: traefik
  image: traefik:brie
  restart: unless-stopped
  command:
     - --experimental.plugins.traefik-real-ip.modulename=github.com/soulbalz/traefik-real-ip
     - --experimental.plugins.traefik-real-ip.version=v1.0.3

middlewares.toml:

[http.middlewares.my-traefik-real-ip]
  [http.middlewares.my-traefik-real-ip.plugin]
    [http.middlewares.my-traefik-real-ip.plugin.traefik-real-ip]
      excludednets = ["192.168.86.0/24", "10.10.0.0/16","172.0.0.0/8"]

Test:

Home Assistant: Invalid IP address in X-Forwarded For: , 192.168.XX.XX

Whats My IP Container result: , 192.168.XX.XX

Same issue with setting excludednets equal to 0.0.0.0/32, 0.0.0.0/0, or any of the individual options above. Seems to work fine for any external IP addresses, just internal causes issues.

Can confirm. Noticed that I could not access home assistant from lan after enabling this plugin. The error log displays
"Invalid IP address in X-Forwarded-For: , 192.168.0.58"

@gionag
Copy link

gionag commented Oct 16, 2022

same for me.
when used from the internal site it fails exactly as @youngT2 and @droans

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants