Merge 781585d9bd3816c52c9319a8fff45bc7a6863e46 into d7eb05b9361febead29a74e71ddffc2ebeff5302
This commit is contained in:
commit
8d574ac513
@ -1109,6 +1109,11 @@ func allowedHostsMiddleware(addr net.Addr) gin.HandlerFunc {
|
||||
|
||||
if addr, err := netip.ParseAddr(host); err == nil {
|
||||
if addr.IsLoopback() || addr.IsPrivate() || addr.IsUnspecified() || isLocalIP(addr) {
|
||||
if c.Request.Method == http.MethodOptions {
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
@ -1140,6 +1145,7 @@ func (s *Server) GenerateRoutes() http.Handler {
|
||||
config.AllowOrigins = envconfig.Origins()
|
||||
|
||||
r := gin.Default()
|
||||
r.HandleMethodNotAllowed = true
|
||||
r.Use(
|
||||
cors.New(config),
|
||||
allowedHostsMiddleware(s.addr),
|
||||
|
Loading…
x
Reference in New Issue
Block a user