Merge 781585d9bd3816c52c9319a8fff45bc7a6863e46 into d7eb05b9361febead29a74e71ddffc2ebeff5302

This commit is contained in:
royjhan 2024-11-14 13:56:28 +08:00 committed by GitHub
commit 8d574ac513
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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),