mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-20 05:52:24 +00:00
fix domain validator
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
This commit is contained in:
parent
315e8af025
commit
d298f4ffbd
1 changed files with 11 additions and 5 deletions
|
@ -3,6 +3,7 @@ package middleware
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
@ -14,12 +15,17 @@ func DomainValidatorMiddleware(domain string) gin.HandlerFunc {
|
||||||
host = c.GetHeader("X-Real-IP")
|
host = c.GetHeader("X-Real-IP")
|
||||||
}
|
}
|
||||||
if host == "" {
|
if host == "" {
|
||||||
host, _, _ := net.SplitHostPort(c.Request.Host)
|
host = c.Request.Host
|
||||||
if host != domain {
|
if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 {
|
||||||
c.AbortWithStatus(http.StatusForbidden)
|
host, _, _ = net.SplitHostPort(host)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
c.Next()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if host != domain {
|
||||||
|
c.AbortWithStatus(http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue