Skip to content

Commit

Permalink
Ensure IPv6 compliant host
Browse files Browse the repository at this point in the history
Co-Authored-By: vnxme <[email protected]>
  • Loading branch information
MHSanaei and vnxme committed May 22, 2024
1 parent 68c9b55 commit e7c59ad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions sub/subController.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sub

import (
"encoding/base64"
"strings"
"net"

"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -54,7 +54,7 @@ func (a *SUBController) initRouter(g *gin.RouterGroup) {

func (a *SUBController) subs(c *gin.Context) {
subId := c.Param("subid")
host := strings.Split(c.Request.Host, ":")[0]
host, _, _ := net.SplitHostPort(c.Request.Host)
subs, header, err := a.subService.GetSubs(subId, host)
if err != nil || len(subs) == 0 {
c.String(400, "Error!")
Expand All @@ -79,7 +79,7 @@ func (a *SUBController) subs(c *gin.Context) {

func (a *SUBController) subJsons(c *gin.Context) {
subId := c.Param("subid")
host := strings.Split(c.Request.Host, ":")[0]
host, _, _ := net.SplitHostPort(c.Request.Host)
jsonSub, header, err := a.subJsonService.GetJson(subId, host)
if err != nil || len(jsonSub) == 0 {
c.String(400, "Error!")
Expand Down
2 changes: 1 addition & 1 deletion web/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func html(c *gin.Context, name string, title string, data gin.H) {
data = gin.H{}
}
data["title"] = title
data["host"] = strings.Split(c.Request.Host, ":")[0]
data["host"], _, _ = net.SplitHostPort(c.Request.Host)
data["request_uri"] = c.Request.RequestURI
data["base_path"] = c.GetString("base_path")
c.HTML(http.StatusOK, name, getContext(data))
Expand Down
4 changes: 2 additions & 2 deletions web/middleware/domainValidator.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package middleware

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

"github.com/gin-gonic/gin"
)

func DomainValidatorMiddleware(domain string) gin.HandlerFunc {
return func(c *gin.Context) {
host := strings.Split(c.Request.Host, ":")[0]
host, _, _ := net.SplitHostPort(c.Request.Host)

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

0 comments on commit e7c59ad

Please sign in to comment.