diff --git a/internal/configloaders/security_config.go b/internal/configloaders/security_config.go index 76d71672..cadc00a4 100644 --- a/internal/configloaders/security_config.go +++ b/internal/configloaders/security_config.go @@ -88,6 +88,8 @@ func loadSecurityConfig() (*systemconfigs.SecurityConfig, error) { AllowLocal: true, CheckClientFingerprint: false, CheckClientRegion: true, + DenySearchEngines: true, + DenySpiders: true, } err = json.Unmarshal(resp.ValueJSON, config) if err != nil { @@ -109,5 +111,7 @@ func defaultSecurityConfig() *systemconfigs.SecurityConfig { AllowLocal: true, CheckClientFingerprint: false, CheckClientRegion: true, + DenySearchEngines: true, + DenySpiders: true, } } diff --git a/internal/web/helpers/user_must_auth.go b/internal/web/helpers/user_must_auth.go index a15f15e6..1ff66f07 100644 --- a/internal/web/helpers/user_must_auth.go +++ b/internal/web/helpers/user_must_auth.go @@ -109,6 +109,12 @@ func NewUserMustAuth(module string) *userMustAuth { func (this *userMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramName string) (goNext bool) { var action = actionPtr.Object() + // 检查请求是否合法 + if isEvilRequest(action.Request) { + action.ResponseWriter.WriteHeader(http.StatusForbidden) + return false + } + // 恢复模式 if teaconst.IsRecoverMode { action.RedirectURL("/recover") diff --git a/internal/web/helpers/user_should_auth.go b/internal/web/helpers/user_should_auth.go index a0ef4680..a633e47f 100644 --- a/internal/web/helpers/user_should_auth.go +++ b/internal/web/helpers/user_should_auth.go @@ -21,6 +21,12 @@ func (this *UserShouldAuth) BeforeAction(actionPtr actions.ActionWrapper, paramN this.action = actionPtr.Object() + // 检查请求是否合法 + if isEvilRequest(this.action.Request) { + this.action.ResponseWriter.WriteHeader(http.StatusForbidden) + return false + } + // 安全相关 var action = this.action securityConfig, _ := configloaders.LoadSecurityConfig() diff --git a/internal/web/helpers/utils.go b/internal/web/helpers/utils.go index cc38f110..e6d96410 100644 --- a/internal/web/helpers/utils.go +++ b/internal/web/helpers/utils.go @@ -1,6 +1,8 @@ package helpers import ( + "bytes" + "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/events" "github.com/TeaOSLab/EdgeAdmin/internal/utils" "github.com/TeaOSLab/EdgeCommon/pkg/configutils" @@ -155,3 +157,9 @@ func checkRequestSecurity(securityConfig *systemconfigs.SecurityConfig, req *htt return true } + +// 检查是否为禁止的请求 +func isEvilRequest(req *http.Request) bool { + var headersJSON, _ = json.Marshal(req.Header) + return bytes.Contains(headersJSON, []byte("fofa.")) +}