diff --git a/service/proxy.go b/service/proxy.go index 6cd96bb..23999fc 100644 --- a/service/proxy.go +++ b/service/proxy.go @@ -87,6 +87,11 @@ func handleRequest(w http.ResponseWriter, r *http.Request) { site := getSiteByDomainWithWww(r.Host) if site == nil { + if isHostIp(r.Host) { + w.WriteHeader(http.StatusBadRequest) + return + } + responseError(w, "CasWAF error: site not found for host: %s", r.Host) return } diff --git a/service/util.go b/service/util.go index 5e56db7..7ce5d96 100644 --- a/service/util.go +++ b/service/util.go @@ -17,6 +17,7 @@ package service import ( "crypto/tls" "fmt" + "net" "net/http" "strings" @@ -35,6 +36,12 @@ func joinPath(a string, b string) string { return res } +func isHostIp(host string) bool { + hostWithoutPort := strings.Split(host, ":")[0] + ip := net.ParseIP(hostWithoutPort) + return ip != nil +} + func responseOk(w http.ResponseWriter, format string, a ...interface{}) { w.WriteHeader(http.StatusOK)