fix(sub): never use X-Real-IP as the subscription host (#6608)

ResolveRequest and the panel's resolveHost fell back to X-Real-IP for the host when a trusted proxy sent no X-Forwarded-Host. X-Real-IP names the visitor, so behind nginx with only that header set, subscription and exported links advertised the subscriber's own public IP as the server.

The host now comes from a trusted X-Forwarded-Host, else the dialed request Host. X-Real-IP stays a client-IP source only.

Fixes #6589.
This commit is contained in:
mrchatam
2026-09-26 22:43:46 +03:30
committed by GitHub
parent 66df77665f
commit 169cd86e00
4 changed files with 54 additions and 16 deletions
+2 -8
View File
@@ -2992,8 +2992,8 @@ type PageData struct {
Emails []string
}
// ResolveRequest extracts scheme and host info from request/headers consistently.
// ResolveRequest extracts scheme, host, and header information from an HTTP request.
// X-Real-IP names the visitor, never the panel, so it is no host source (#6589).
func (s *SubService) ResolveRequest(c *gin.Context) (scheme string, host string, hostWithPort string, hostHeader string) {
trusted := s.forwardedHeadersTrusted(c)
if !trusted {
@@ -3012,13 +3012,10 @@ func (s *SubService) ResolveRequest(c *gin.Context) (scheme string, host string,
scheme = "https"
}
// base host (no port)
// base host (no port): trusted X-Forwarded-Host, then the dialed request Host.
if h, err := getHostFromXFH(forwarded("X-Forwarded-Host")); err == nil && h != "" {
host = h
}
if host == "" {
host = forwarded("X-Real-IP")
}
if host == "" {
var err error
host, _, err = net.SplitHostPort(c.Request.Host)
@@ -3038,9 +3035,6 @@ func (s *SubService) ResolveRequest(c *gin.Context) (scheme string, host string,
// header display host
hostHeader = forwarded("X-Forwarded-Host")
if hostHeader == "" {
hostHeader = forwarded("X-Real-IP")
}
if hostHeader == "" {
hostHeader = host
}