优化客服云权限安全与访客IP解析

This commit is contained in:
yml2213
2026-08-31 13:43:45 +08:00
parent 523a306d5e
commit bdf67395ab
24 changed files with 365 additions and 48 deletions
+3 -1
View File
@@ -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 == "" {