优化客服云权限安全与访客IP解析
This commit is contained in:
@@ -12,7 +12,6 @@ func resolveVisitorIP(c *gin.Context) string {
|
||||
candidates := []string{
|
||||
c.GetHeader("CF-Connecting-IP"),
|
||||
c.GetHeader("True-Client-IP"),
|
||||
c.GetHeader("X-Real-IP"),
|
||||
}
|
||||
if xff := c.GetHeader("X-Forwarded-For"); xff != "" {
|
||||
// 取最左侧第一个非空 IP
|
||||
@@ -24,6 +23,9 @@ func resolveVisitorIP(c *gin.Context) string {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Nginx 经 Caddy/网关转发时,X-Real-IP 通常是上一跳代理地址;
|
||||
// X-Forwarded-For 才包含访客地址,因此放在 XFF 之后作为回退。
|
||||
candidates = append(candidates, c.GetHeader("X-Real-IP"))
|
||||
for _, raw := range candidates {
|
||||
ip := strings.TrimSpace(raw)
|
||||
if ip == "" {
|
||||
|
||||
Reference in New Issue
Block a user