Fix domain validation for Nginx/CDN compatibility #2450

This commit is contained in:
mhsanaei 2024-08-08 10:52:59 +02:00
parent 7b8ef98846
commit 1a24c386ce

View file

@ -11,15 +11,13 @@ import (
func DomainValidatorMiddleware(domain string) gin.HandlerFunc {
return func(c *gin.Context) {
host := c.GetHeader("X-Forwarded-Host")
if host == "" {
host = c.GetHeader("X-Real-IP")
}
if host == "" {
host = c.Request.Host
}
if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 {
host, _, _ = net.SplitHostPort(host)
}
}
if host != domain {
c.AbortWithStatus(http.StatusForbidden)