mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 12:20:28 +08:00
增强安全性
This commit is contained in:
@@ -88,6 +88,8 @@ func loadSecurityConfig() (*systemconfigs.SecurityConfig, error) {
|
|||||||
AllowLocal: true,
|
AllowLocal: true,
|
||||||
CheckClientFingerprint: false,
|
CheckClientFingerprint: false,
|
||||||
CheckClientRegion: true,
|
CheckClientRegion: true,
|
||||||
|
DenySearchEngines: true,
|
||||||
|
DenySpiders: true,
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(resp.ValueJSON, config)
|
err = json.Unmarshal(resp.ValueJSON, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -109,5 +111,7 @@ func defaultSecurityConfig() *systemconfigs.SecurityConfig {
|
|||||||
AllowLocal: true,
|
AllowLocal: true,
|
||||||
CheckClientFingerprint: false,
|
CheckClientFingerprint: false,
|
||||||
CheckClientRegion: true,
|
CheckClientRegion: true,
|
||||||
|
DenySearchEngines: true,
|
||||||
|
DenySpiders: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,12 @@ func NewUserMustAuth(module string) *userMustAuth {
|
|||||||
func (this *userMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramName string) (goNext bool) {
|
func (this *userMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramName string) (goNext bool) {
|
||||||
var action = actionPtr.Object()
|
var action = actionPtr.Object()
|
||||||
|
|
||||||
|
// 检查请求是否合法
|
||||||
|
if isEvilRequest(action.Request) {
|
||||||
|
action.ResponseWriter.WriteHeader(http.StatusForbidden)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// 恢复模式
|
// 恢复模式
|
||||||
if teaconst.IsRecoverMode {
|
if teaconst.IsRecoverMode {
|
||||||
action.RedirectURL("/recover")
|
action.RedirectURL("/recover")
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ func (this *UserShouldAuth) BeforeAction(actionPtr actions.ActionWrapper, paramN
|
|||||||
|
|
||||||
this.action = actionPtr.Object()
|
this.action = actionPtr.Object()
|
||||||
|
|
||||||
|
// 检查请求是否合法
|
||||||
|
if isEvilRequest(this.action.Request) {
|
||||||
|
this.action.ResponseWriter.WriteHeader(http.StatusForbidden)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// 安全相关
|
// 安全相关
|
||||||
var action = this.action
|
var action = this.action
|
||||||
securityConfig, _ := configloaders.LoadSecurityConfig()
|
securityConfig, _ := configloaders.LoadSecurityConfig()
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
@@ -155,3 +157,9 @@ func checkRequestSecurity(securityConfig *systemconfigs.SecurityConfig, req *htt
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否为禁止的请求
|
||||||
|
func isEvilRequest(req *http.Request) bool {
|
||||||
|
var headersJSON, _ = json.Marshal(req.Header)
|
||||||
|
return bytes.Contains(headersJSON, []byte("fofa."))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user