mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6608] [MERGED] fix(sub): never use X-Real-IP as the subscription host #6375
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#6375
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?
📋 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)
f6ca990fix(sub): never use X-Real-IP as the subscription host562615afix(web): stop resolveHost from using X-Real-IP as a hostnamed91afe9style(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 toX-Real-IPforhost/hostHeader.resolveHost(inbound/client share-link APIs) no longer falls back toX-Real-IPeither — same leak when nginx on loopback sets only that header.X-Forwarded-Host→ dialedRequest.Host.X-Real-IPremains 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-IPbut notX-Forwarded-Host(common default), subscription and panel-exported links advertised the subscriber's/admin's public IP asserverwhenever 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=1go test ./internal/web/controller/ -count=1 -run 'TestResolveHost|TestGetRemoteIp'X-Real-IP, fetch/clash/<subid>and confirmserver:is the panel host (orRequest.Host), not the client IPX-Forwarded-Hostset 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.