mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6589] [Bug]: Subscription links advertise the client's public IP as the server address behind a reverse proxy (X-Real-IP used as host) #4414
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4414
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sy3tem on GitHub (Sep 17, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6589
Describe the bug
The
serverfield in subscription output (raw/sub,/json,/clash) is filled with the subscriber's own public IP instead of the panel's public host. The value changes depending on which client machine fetches the subscription, so imported profiles point at the wrong host and the VPN does not route correctly.I reproduced this on the current
main(v3.8.5 era, main HEAD1c0ce80). The panel is deployed behind anopenresty/nginx reverse proxy.Example subscription URL:
https://<your-domain>/clash/<subid>Decoded response:
<client-public-ip>is the visitor's public IP, not the panel host. Fetching the same URL from another machine yields that other machine's IP inserver.How to reproduce
X-Real-IPto the visitor's IP but does not setX-Forwarded-Host(common default for nginx/openresty and several CDN setups).subDomain) / web domain setting.0.0.0.0) listen.https://<your-domain>/clash/<subid>from a client.server:in the YAML equals that client's public IP.Expected behavior
The
serverfield should be stable and reflect the panel's public host (<your-domain>), or at minimum the value configured insubDomain/webDomain, or the actualHostheader the client dialed - never the client IP.Actual behavior
serveris set to the requesting client's public IP whenever no node address / routable listen address / configured public host is present.Root cause (source analysis)
In
internal/sub/service.go,SubService.ResolveRequestderives the host in this order:When the proxy sends
X-Real-IPbut notX-Forwarded-Host,hostbecomes the visitor's public IP. (Note: nginx/openresty forwards the originalHostheader by default, so the correct panel domain is actually available atc.Request.Host- it is simply skipped becauseX-Real-IPis checked first.)That
hostis then stored ass.addressviaForRequest(host)?PrepareForRequest, andresolveInboundAddress(alsointernal/sub/service.go) falls back tos.addresswhen nothing else is available:So with no
subDomain/webDomainconfigured and no node/routable listen address, the link advertises the client IP.Suggested fix
X-Real-IPis a client identifier, not a host. Prefer the actualHostheader the client dialed over it. Reorder host resolution to:When
X-Forwarded-Hostis absent,c.Request.Hostalready carries the real panel domain, so no client IP leaks in.Related (previously closed) reports - this is a remaining gap
The prior fix (#5208 / #5425) added the
configuredPublicHost()fallback insideresolveInboundAddress, which only helps whensubDomain/webDomainis set. The underlyingX-Real-IP-as-host leak inResolveRequestremains, which is why this still reproduces when the public host setting is empty.Workaround (for other users)
Set the Subscription domain (
subDomain) (or web domain) to your panel host, e.g.https://<your-domain>;resolveInboundAddressthen uses it instead of the leaked IP.Checklist
main).@CNYANGANG commented on GitHub (Sep 28, 2026):
修改分享地址策略地址或添加 proxy_set_header X-Forwarded-Host $host;就可以了。