Skip to content

Commit

Permalink
fix domain validator
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza0 committed Jul 18, 2024
1 parent 58f4a67 commit b2d0134
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion backend/middleware/domainValidator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package middleware

import (
"net"
"net/http"
"strings"

Expand All @@ -9,7 +10,10 @@ import (

func DomainValidator(domain string) gin.HandlerFunc {
return func(c *gin.Context) {
host := strings.Split(c.Request.Host, ":")[0]
host := c.Request.Host
if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 {
host, _, _ = net.SplitHostPort(c.Request.Host)
}

if host != domain {
c.AbortWithStatus(http.StatusForbidden)
Expand Down

0 comments on commit b2d0134

Please sign in to comment.