Skip to content

Commit 005e25c

Browse files
committed
增强安全性
1 parent 711e36d commit 005e25c

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

internal/configloaders/security_config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func loadSecurityConfig() (*systemconfigs.SecurityConfig, error) {
8888
AllowLocal: true,
8989
CheckClientFingerprint: false,
9090
CheckClientRegion: true,
91+
DenySearchEngines: true,
92+
DenySpiders: true,
9193
}
9294
err = json.Unmarshal(resp.ValueJSON, config)
9395
if err != nil {
@@ -109,5 +111,7 @@ func defaultSecurityConfig() *systemconfigs.SecurityConfig {
109111
AllowLocal: true,
110112
CheckClientFingerprint: false,
111113
CheckClientRegion: true,
114+
DenySearchEngines: true,
115+
DenySpiders: true,
112116
}
113117
}

internal/web/helpers/user_must_auth.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ func NewUserMustAuth(module string) *userMustAuth {
109109
func (this *userMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramName string) (goNext bool) {
110110
var action = actionPtr.Object()
111111

112+
// 检查请求是否合法
113+
if isEvilRequest(action.Request) {
114+
action.ResponseWriter.WriteHeader(http.StatusForbidden)
115+
return false
116+
}
117+
112118
// 恢复模式
113119
if teaconst.IsRecoverMode {
114120
action.RedirectURL("/recover")

internal/web/helpers/user_should_auth.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ func (this *UserShouldAuth) BeforeAction(actionPtr actions.ActionWrapper, paramN
2121

2222
this.action = actionPtr.Object()
2323

24+
// 检查请求是否合法
25+
if isEvilRequest(this.action.Request) {
26+
this.action.ResponseWriter.WriteHeader(http.StatusForbidden)
27+
return false
28+
}
29+
2430
// 安全相关
2531
var action = this.action
2632
securityConfig, _ := configloaders.LoadSecurityConfig()

internal/web/helpers/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package helpers
22

33
import (
4+
"bytes"
5+
"encoding/json"
46
"github.com/TeaOSLab/EdgeAdmin/internal/events"
57
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
68
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
@@ -155,3 +157,9 @@ func checkRequestSecurity(securityConfig *systemconfigs.SecurityConfig, req *htt
155157

156158
return true
157159
}
160+
161+
// 检查是否为禁止的请求
162+
func isEvilRequest(req *http.Request) bool {
163+
var headersJSON, _ = json.Marshal(req.Header)
164+
return bytes.Contains(headersJSON, []byte("fofa."))
165+
}

0 commit comments

Comments
 (0)