Source IP doesn't get registered using xHTTP protocol in some cases
I was messing around with xHTTP and its powerful ability to separate downstream and upstream. I noticed when creating a simple xHTTP inbound with no tls/reality(tls termination done by nginx and reality is a separate inbound), the source IP doesn't get registered in some client configurations which I list below:
- Reality: N
- TLS(CDN): Y
- Reality Upstream/TLS(CDN) DownStream: Y
- TLS(CDN) Upstream/Reality DownStream: N
Log for 1:
2025/01/28 19:28:31 DOHL//one.one.one.one got answer: api.github.com -> [140.82.114.5] 4.593819ms
2025/01/28 19:28:31 from 127.0.0.1:18752 accepted tcp:api.github.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:28:32 DOHL//one.one.one.one cache HIT: www.google.com -> [108.177.121.106, 108.177.121.105, 108.177.121.99, 108.177.121.103, 108.177.121.147, 108.177.121>
2025/01/28 19:28:40 from 127.0.0.1:27630 accepted tcp:127.0.0.1:0 [api -> api]
2025/01/28 19:28:50 from 127.0.0.1:44432 accepted tcp:127.0.0.1:0 [api -> api]
2025/01/28 19:28:55 DOHL//one.one.one.one cache HIT: www.speedtest.net -> [104.17.147.22, 104.17.148.22]
2025/01/28 19:28:55 from 127.0.0.1:18752 accepted tcp:www.speedtest.net:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:28:57 DOHL//one.one.one.one cache HIT: b.cdnst.net -> [2a04:4e42::731, 2a04:4e42:200::731, 2a04:4e42:400::731, 2a04:4e42:600::731]
2025/01/28 19:28:57 from 127.0.0.1:18752 accepted tcp:b.cdnst.net:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:28:57 DOHL//one.one.one.one got answer: cdn.ziffstatic.com -> [104.93.21.154, 104.93.21.160, 2600:1407:7400:21::172f:4810, 2600:1407:7400:21::172f:480d] >
2025/01/28 19:28:57 from 127.0.0.1:18752 accepted tcp:cdn.ziffstatic.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:28:58 DOHL//one.one.one.one got answer: cdn.cookielaw.org -> [104.18.86.42, 104.18.87.42, 2606:4700::6812:572a, 2606:4700::6812:562a] 4.502849ms
2025/01/28 19:28:58 from 127.0.0.1:18752 accepted tcp:cdn.cookielaw.org:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
Log for 2:
2025/01/28 19:33:55 DOHL//one.one.one.one cache HIT: github.githubassets.com -> [185.199.110.154, 185.199.111.154, 185.199.109.154, 185.199.108.154]
2025/01/28 19:33:55 from 164.215.*.*:0 accepted tcp:github.githubassets.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:33:55 DOHL//one.one.one.one cache HIT: github.githubassets.com -> [185.199.110.154, 185.199.111.154, 185.199.109.154, 185.199.108.154]
2025/01/28 19:33:55 from 164.215.*.*:0 accepted tcp:github.githubassets.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:33:55 DOHL//one.one.one.one cache HIT: github.githubassets.com -> [185.199.110.154, 185.199.111.154, 185.199.109.154, 185.199.108.154]
2025/01/28 19:33:55 from 164.215.*.*:0 accepted tcp:github.githubassets.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:33:58 DOHL//one.one.one.one cache HIT: avatars.githubusercontent.com -> [185.199.108.133, 185.199.109.133, 185.199.110.133, 185.199.111.133, 2606:50c0:80>
2025/01/28 19:33:58 from 164.215.*.*:0 accepted tcp:avatars.githubusercontent.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa000.DIRECT
2025/01/28 19:33:58 DOHL//one.one.one.one cache HIT: avatars.githubusercontent.com -> [185.199.108.133, 185.199.109.133, 185.199.110.133, 185.199.111.133, 2606:50c0:80>
2025/01/28 19:33:58 from 164.215.*.*:0 accepted tcp:avatars.githubusercontent.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:33:58 DOHL//one.one.one.one got answer: speedtest.layer2networks.net.prod.hosts.ooklaserver.net -> [216.250.126.169, 2607:f1c0:f037:9200::1] 41.219235ms
2025/01/28 19:33:58 from 164.215.*.*:0 accepted tcp:speedtest.layer2networks.net.prod.hosts.ooklaserver.net:8080 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.>
2025/01/28 19:33:59 DOHL//one.one.one.one got answer: speedtest.us-la.kamatera.com.prod.hosts.ooklaserver.net -> [45.61.57.19] 9.040012ms
Log for 3:
2025/01/28 19:39:27 from 164.215.*.*:0 accepted tcp:api.github.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:39:27 DOHL//one.one.one.one got answer: cdn.ziffstatic.com -> [104.93.21.154, 104.93.21.160, 2600:1407:7400:21::172f:480f, 2600:1407:7400:21::172f:4810] >
2025/01/28 19:39:27 from 164.215.*.*:0 accepted tcp:cdn.ziffstatic.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:39:27 DOHL//one.one.one.one got answer: github.com -> [140.82.112.3] 7.49383ms
2025/01/28 19:39:27 from 164.215.*.*:0 accepted tcp:github.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:39:27 DOHL//one.one.one.one got answer: b.cdnst.net -> [151.101.2.219, 151.101.66.219, 151.101.130.219, 151.101.194.219, 2a04:4e42::731, 2a04:4e42:200::7>
2025/01/28 19:39:27 from 164.215.*.*:0 accepted tcp:b.cdnst.net:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:39:27 DOHL//one.one.one.one cache HIT: github.com -> [140.82.112.3]
2025/01/28 19:39:27 from 164.215.*.*:0 accepted tcp:github.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:39:29 DOHL//one.one.one.one got answer: github.githubassets.com -> [185.199.109.154, 185.199.108.154, 185.199.111.154, 185.199.110.154] 8.105242ms
Log for 4:
2025/01/28 19:43:25 DOHL//one.one.one.one cache HIT: cdn.cookielaw.org -> [104.18.87.42, 104.18.86.42, 2606:4700::6812:562a, 2606:4700::6812:572a]
2025/01/28 19:43:25 from 127.0.0.1:43248 accepted tcp:cdn.cookielaw.org:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa000.DIRECT
2025/01/28 19:43:26 DOHL//one.one.one.one cache HIT: b.cdnst.net -> [151.101.2.219, 151.101.66.219, 151.101.130.219, 151.101.194.219, 2a04:4e42:400::731, 2a04:4e42:200>
2025/01/28 19:43:26 from 127.0.0.1:43248 accepted tcp:b.cdnst.net:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa000.DIRECT
2025/01/28 19:43:26 DOHL//one.one.one.one cache HIT: cdn.cookielaw.org -> [104.18.87.42, 104.18.86.42, 2606:4700::6812:562a, 2606:4700::6812:572a]
2025/01/28 19:43:26 from 127.0.0.1:43248 accepted tcp:cdn.cookielaw.org:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:43:26 DOHL//one.one.one.one cache HIT: cdn.cookielaw.org -> [104.18.87.42, 104.18.86.42, 2606:4700::6812:562a, 2606:4700::6812:572a]
2025/01/28 19:43:26 from 127.0.0.1:43248 accepted tcp:cdn.cookielaw.org:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:43:26 DOHL//one.one.one.one cache HIT: github.com -> [140.82.114.3]
2025/01/28 19:43:26 from 127.0.0.1:43248 accepted tcp:github.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:43:26 DOHL//one.one.one.one cache HIT: github.com -> [140.82.114.3]
2025/01/28 19:43:26 from 127.0.0.1:43248 accepted tcp:github.com:443 [inbound-127.0.0.1:3010 >> direct] email: Mostafa.DIRECT
2025/01/28 19:43:29 DOHL//one.one.one.one cache HIT: speedtest.layer2networks.net.prod.hosts.ooklaserver.net -> [216.250.126.169, 2607:f1c0:f037:9200::1]
2025/01/28 19:43:29 from 127.0.0.1:43248 accepted tcp:speedtest.layer2networks.net.prod.hosts.ooklaserver.net:8080 [inbound-127.0.0.1:3010 >> direct] email: Mostafa000>
2025/01/28 19:43:29 DOHL//one.one.one.one cache HIT: speedtest.us-la.kamatera.com.prod.hosts.ooklaserver.net -> [45.61.57.19]
Here is my inbounds:
{
"listen": "127.0.0.1",
"port": 3010,
"protocol": "vless",
"settings": {
"clients": [
{
"email": "Mostafa.DIRECT",
"flow": "",
"id": "UUID"
}
],
"decryption": "none",
"fallbacks": []
},
"streamSettings": {
"network": "xhttp",
"security": "none",
"xhttpSettings": {
"headers": {},
"host": "",
"mode": "auto",
"noSSEHeader": false,
"path": "/myPath",
"scMaxBufferedPosts": 30,
"scMaxEachPostBytes": "1000000",
"xPaddingBytes": "100-1000"
}
}
...
{
"listen": "127.0.0.3",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
...
}
],
"decryption": "none",
"fallbacks": [
{
"alpn": "",
"dest": "3010",
"name": "",
"path": "",
"xver": 0
}
]
},
"streamSettings": {
"network": "tcp",
"realitySettings": {
"dest": "443",
"maxClient": "",
"maxTimediff": 0,
"minClient": "",
"privateKey": "KEY",
"serverNames": [
"myOwnDomain"
],
"shortIds": [
"myShortIds"
],
"show": false,
"xver": 2
},
"security": "reality",
"tcpSettings": {
"acceptProxyProtocol": true,
"header": {
"type": "none"
}
}
}
I use HAproxy and nginx for reverse proxy and web-server and X-Forwarded-For is used to maintain the source IP.
因为日志只能log一个ip 最开始的设计里下行连接只会有一个而上行可能有多个甚至源于多个不同ip都是有可能的 所以选择了只list下行连接的ip打印日志
I didn't fully understand your comment but, it seems Xray gets the client's IP from the client's downstream. By implementing fallback (without proxy-protocol) which is necessary to establish a separate upstream/downstream, the IP vanishes. Now, you can either get the IP by activating proxy-protocol or you can add other mechanisms for maintaining IP such as getting IP from the client's upstream. Either way, it would be much appreciated if you implement such features.