mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-06 10:00:25 +08:00
网站设置增加是否支持${serverAddr}选项/增强${serverAddr}安全性
This commit is contained in:
@@ -855,13 +855,19 @@ func (this *HTTPRequest) Format(source string) string {
|
|||||||
case "serverName":
|
case "serverName":
|
||||||
return this.ServerName
|
return this.ServerName
|
||||||
case "serverAddr":
|
case "serverAddr":
|
||||||
var requestConn = this.RawReq.Context().Value(HTTPConnContextKey)
|
var nodeConfig = this.nodeConfig
|
||||||
if requestConn != nil {
|
if nodeConfig != nil && nodeConfig.GlobalServerConfig != nil && nodeConfig.GlobalServerConfig.HTTPAll.EnableServerAddrVariable {
|
||||||
conn, ok := requestConn.(net.Conn)
|
if len(this.requestRemoteAddrs()) > 1 {
|
||||||
if ok {
|
return "" // hidden for security
|
||||||
host, _, _ := net.SplitHostPort(conn.LocalAddr().String())
|
}
|
||||||
if len(host) > 0 {
|
var requestConn = this.RawReq.Context().Value(HTTPConnContextKey)
|
||||||
return host
|
if requestConn != nil {
|
||||||
|
conn, ok := requestConn.(net.Conn)
|
||||||
|
if ok {
|
||||||
|
host, _, _ := net.SplitHostPort(conn.LocalAddr().String())
|
||||||
|
if len(host) > 0 {
|
||||||
|
return host
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1234,7 +1240,7 @@ func (this *HTTPRequest) requestRemoteAddrs() (result []string) {
|
|||||||
var forwardedFor = this.RawReq.Header.Get("X-Forwarded-For")
|
var forwardedFor = this.RawReq.Header.Get("X-Forwarded-For")
|
||||||
if len(forwardedFor) > 0 {
|
if len(forwardedFor) > 0 {
|
||||||
commaIndex := strings.Index(forwardedFor, ",")
|
commaIndex := strings.Index(forwardedFor, ",")
|
||||||
if commaIndex > 0 {
|
if commaIndex > 0 && !lists.ContainsString(result, forwardedFor[:commaIndex]) {
|
||||||
result = append(result, forwardedFor[:commaIndex])
|
result = append(result, forwardedFor[:commaIndex])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1242,7 +1248,7 @@ func (this *HTTPRequest) requestRemoteAddrs() (result []string) {
|
|||||||
// Real-IP
|
// Real-IP
|
||||||
{
|
{
|
||||||
realIP, ok := this.RawReq.Header["X-Real-IP"]
|
realIP, ok := this.RawReq.Header["X-Real-IP"]
|
||||||
if ok && len(realIP) > 0 {
|
if ok && len(realIP) > 0 && !lists.ContainsString(result, realIP[0]) {
|
||||||
result = append(result, realIP[0])
|
result = append(result, realIP[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1250,7 +1256,7 @@ func (this *HTTPRequest) requestRemoteAddrs() (result []string) {
|
|||||||
// Real-Ip
|
// Real-Ip
|
||||||
{
|
{
|
||||||
realIP, ok := this.RawReq.Header["X-Real-Ip"]
|
realIP, ok := this.RawReq.Header["X-Real-Ip"]
|
||||||
if ok && len(realIP) > 0 {
|
if ok && len(realIP) > 0 && !lists.ContainsString(result, realIP[0]) {
|
||||||
result = append(result, realIP[0])
|
result = append(result, realIP[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1260,7 +1266,9 @@ func (this *HTTPRequest) requestRemoteAddrs() (result []string) {
|
|||||||
var remoteAddr = this.RawReq.RemoteAddr
|
var remoteAddr = this.RawReq.RemoteAddr
|
||||||
host, _, err := net.SplitHostPort(remoteAddr)
|
host, _, err := net.SplitHostPort(remoteAddr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
result = append(result, host)
|
if !lists.ContainsString(result, host) {
|
||||||
|
result = append(result, host)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result = append(result, remoteAddr)
|
result = append(result, remoteAddr)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user