yisier / nps

在 0.26.10 版本的基础上修改而来的
https://ehang.io/nps/documents
GNU General Public License v3.0
1.8k stars 219 forks source link

域名解析时,X_Forwarded_for出现多余内容 #153

Closed Oaklight closed 4 months ago

Oaklight commented 5 months ago

Describe the bug 在设置home assistant的域名访问时,发现log里面出现invalid ip (是因为多了port info,但与issue问题无关),格式如下: [homeassistant.components.http.forwarded] Invalid IP address in X-Forwarded-For: xx.xx.xx.xx:19744, [ 而使用caddy做反向代理的时候访问同样地址,log则是: [homeassistant.components.http.forwarded] Invalid IP address in X-Forwarded-For: xx.xx.xx.xx:19757 对比之后发现,nps的域名代理会在log的X-Forwarded-For信息里面多出一个, [

To Reproduce Steps to reproduce the behavior:

  1. home assistant运行在localhost:8123。也可用TCP tunnel先包裹一层,比如12312代理到8123。然后分别用caddy或nps做域名代理。
  2. caddy 设置域名reverse proxy时,handle包含:
        header_up X-Real-IP {http.request.remote}
        header_up X-Forwarded-For {http.request.remote}
        header_up X-Forwarded-Port {http.request.port}
        header_up X-Forwarded-Proto {http.request.scheme}

    观察home-assistant.log会发现[homeassistant.components.http.forwarded] Invalid IP address in X-Forwarded-For: xx.xx.xx.xx:19757

  3. 用caddy将2中handle的同样内容导入nps,nps段设置域名代理访问localhost:8123,观察log发现[homeassistant.components.http.forwarded] Invalid IP address in X-Forwarded-For: xx.xx.xx.xx:19744, [
  4. 可反复多次对比复现。

Expected behavior 不应该出现, [

Screenshots or logs image

Server (please complete the following information):

Client (please complete the following information):

Additional context N/A

yisier commented 4 months ago

没有复现,nps 不会拼接 ‘, [’ 这种符号的,你排查下别的原因吧