[PR #6608] [MERGED] fix(sub): never use X-Real-IP as the subscription host #6375

Closed
opened 2026-11-02 04:08:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6608
Author: @mrchatam
Created: 9/19/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @MHSanaei

Base: main ← Head: fix/sub-resolve-request-no-real-ip-as-host


📝 Commits (3)

  • f6ca990 fix(sub): never use X-Real-IP as the subscription host
  • 562615a fix(web): stop resolveHost from using X-Real-IP as a hostname
  • d91afe9 style(sub): keep the X-Real-IP host comments to two lines

📊 Changes

4 files changed (+54 additions, -16 deletions)

View changed files

📝 internal/sub/forwarded_trust_test.go (+23 -0)
📝 internal/sub/service.go (+2 -8)
📝 internal/web/controller/inbound.go (+2 -8)
📝 internal/web/controller/util_test.go (+27 -0)

📄 Description

Summary

  • ResolveRequest (subscription /sub, /json, /clash) no longer falls back to X-Real-IP for host / hostHeader.
  • Panel resolveHost (inbound/client share-link APIs) no longer falls back to X-Real-IP either — same leak when nginx on loopback sets only that header.
  • Order is now: trusted X-Forwarded-Host → dialed Request.Host.
  • X-Real-IP remains used for client IP extraction (getRemoteIp) and for forwarded-header trust detection; it is never treated as a hostname.

Behind nginx/openresty that sets X-Real-IP but not X-Forwarded-Host (common default), subscription and panel-exported links advertised the subscriber's/admin's public IP as server whenever no node address / subDomain / routable listen was configured.

Fixes #6589

Test plan

  • go test ./internal/sub/ -count=1 -run 'TestResolveRequest|TestHasForwarded|TestRemoteAddrInCIDRs'
  • go test ./internal/sub/ -count=1
  • go test ./internal/web/controller/ -count=1 -run 'TestResolveHost|TestGetRemoteIp'
  • Behind a reverse proxy that sets only X-Real-IP, fetch /clash/<subid> and confirm server: is the panel host (or Request.Host), not the client IP
  • Same proxy: Export All URLs / client links from the panel use the panel host, not the visitor IP
  • With X-Forwarded-Host set from a trusted proxy, confirm that host is still preferred

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6608 **Author:** [@mrchatam](https://github.com/mrchatam) **Created:** 9/19/2026 **Status:** ✅ Merged **Merged:** 9/26/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/sub-resolve-request-no-real-ip-as-host` --- ### 📝 Commits (3) - [`f6ca990`](https://github.com/MHSanaei/3x-ui/commit/f6ca990dccc6c1f55fb314969b021d0296de7505) fix(sub): never use X-Real-IP as the subscription host - [`562615a`](https://github.com/MHSanaei/3x-ui/commit/562615a302d76adeff4bf4d752e3aaaea63cf37f) fix(web): stop resolveHost from using X-Real-IP as a hostname - [`d91afe9`](https://github.com/MHSanaei/3x-ui/commit/d91afe9fac118c9ab08d4a553162bfa44a584c46) style(sub): keep the X-Real-IP host comments to two lines ### 📊 Changes **4 files changed** (+54 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `internal/sub/forwarded_trust_test.go` (+23 -0) 📝 `internal/sub/service.go` (+2 -8) 📝 `internal/web/controller/inbound.go` (+2 -8) 📝 `internal/web/controller/util_test.go` (+27 -0) </details> ### 📄 Description ## Summary - `ResolveRequest` (subscription `/sub`, `/json`, `/clash`) no longer falls back to `X-Real-IP` for `host` / `hostHeader`. - Panel `resolveHost` (inbound/client share-link APIs) no longer falls back to `X-Real-IP` either — same leak when nginx on loopback sets only that header. - Order is now: trusted `X-Forwarded-Host` → dialed `Request.Host`. - `X-Real-IP` remains used for **client IP** extraction (`getRemoteIp`) and for forwarded-header trust detection; it is never treated as a hostname. Behind nginx/openresty that sets `X-Real-IP` but not `X-Forwarded-Host` (common default), subscription and panel-exported links advertised the **subscriber's/admin's public IP** as `server` whenever no node address / `subDomain` / routable listen was configured. Fixes #6589 ## Test plan - [x] `go test ./internal/sub/ -count=1 -run 'TestResolveRequest|TestHasForwarded|TestRemoteAddrInCIDRs'` - [x] `go test ./internal/sub/ -count=1` - [x] `go test ./internal/web/controller/ -count=1 -run 'TestResolveHost|TestGetRemoteIp'` - [ ] Behind a reverse proxy that sets only `X-Real-IP`, fetch `/clash/<subid>` and confirm `server:` is the panel host (or `Request.Host`), not the client IP - [ ] Same proxy: Export All URLs / client links from the panel use the panel host, not the visitor IP - [ ] With `X-Forwarded-Host` set from a trusted proxy, confirm that host is still preferred --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:18 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6375
No description provided.