fix11: runtime contracts and smoke stability

This commit is contained in:
2026-04-30 21:50:03 +05:00
parent 4a0d9569d1
commit a41f14067b
10 changed files with 105 additions and 88 deletions
+12 -5
View File
@@ -2,7 +2,6 @@ package middleware
import (
"github.com/gin-gonic/gin"
"hy2xs-admin/model/vo"
"net/http"
"regexp"
)
@@ -11,13 +10,21 @@ func FilterHandler() gin.HandlerFunc {
return func(c *gin.Context) {
matched, err := regexp.MatchString(`(?i)fofa|shodan|curl|wget`, c.Request.UserAgent())
if err != nil {
vo.Fail("Internal error", c)
c.AbortWithStatus(http.StatusInternalServerError)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"code": http.StatusInternalServerError,
"type": "no",
"message": "Internal error",
"data": nil,
})
return
}
if matched {
vo.Fail("Forbidden: Scanning tools are not allowed", c)
c.AbortWithStatus(http.StatusForbidden)
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{
"code": http.StatusForbidden,
"type": "no",
"message": "Forbidden: Scanning tools are not allowed",
"data": nil,
})
return
}
c.Next()
+6 -3
View File
@@ -5,7 +5,6 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"hy2xs-admin/model/vo"
)
func LocalOnlyHandler() gin.HandlerFunc {
@@ -16,8 +15,12 @@ func LocalOnlyHandler() gin.HandlerFunc {
}
if host != "127.0.0.1" && host != "::1" {
vo.Fail("local access only", c)
c.AbortWithStatus(http.StatusForbidden)
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{
"code": http.StatusForbidden,
"type": "no",
"message": "local access only",
"data": nil,
})
return
}
+7 -3
View File
@@ -4,7 +4,7 @@ import (
"github.com/didip/tollbooth"
"github.com/didip/tollbooth/limiter"
"github.com/gin-gonic/gin"
"hy2xs-admin/model/vo"
"net/http"
)
var limit *limiter.Limiter
@@ -17,8 +17,12 @@ func RateLimiterHandler() gin.HandlerFunc {
return func(c *gin.Context) {
httpError := tollbooth.LimitByRequest(limit, c.Writer, c.Request)
if httpError != nil {
vo.Fail("click too fast", c)
c.Abort()
c.AbortWithStatusJSON(http.StatusTooManyRequests, gin.H{
"code": http.StatusTooManyRequests,
"type": "no",
"message": "click too fast",
"data": nil,
})
return
}
c.Next()