fix version 1
This commit is contained in:
@@ -3,7 +3,7 @@ package log
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"strings"
|
||||
"net"
|
||||
|
||||
"bsm/full/module/base/logs/internal/impl"
|
||||
"bsm/full/module/base/logs/internal/models"
|
||||
@@ -16,9 +16,8 @@ func Create(c *gin.Context) {
|
||||
request = make([]*models.LogData, 0)
|
||||
)
|
||||
|
||||
// 验证请求IP,禁止公网网段提交
|
||||
ip := c.ClientIP()
|
||||
if ip == "127.0.0.1" || ip == "localhost" || strings.HasPrefix(ip, "10.") || strings.HasPrefix(ip, "172.") || strings.HasPrefix(ip, "192.") {
|
||||
// 验证请求IP:仅允许内网/本机地址提交,禁止公网网段提交
|
||||
if !isPrivateIP(c.ClientIP()) {
|
||||
log.Printf("request ip is not allowed")
|
||||
err := errors.New("request ip is not allowed")
|
||||
infra.Response.Error(c, err)
|
||||
@@ -45,3 +44,15 @@ func Create(c *gin.Context) {
|
||||
|
||||
infra.Response.Success(c, "")
|
||||
}
|
||||
|
||||
// isPrivateIP 判断是否为内网或本机地址
|
||||
func isPrivateIP(ip string) bool {
|
||||
if ip == "localhost" {
|
||||
return true
|
||||
}
|
||||
parsed := net.ParseIP(ip)
|
||||
if parsed == nil {
|
||||
return false
|
||||
}
|
||||
return parsed.IsLoopback() || parsed.IsPrivate()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user