From 2d8353463680e9414ca6ef26438552cc6f7171d4 Mon Sep 17 00:00:00 2001 From: zhyale Date: Sun, 20 Mar 2022 18:30:50 +0800 Subject: [PATCH] remove redundant code from CC check and let it go directly when CC policy is OK_PASS --- firewall/cc.go | 7 +------ gateway/gateway.go | 2 ++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/firewall/cc.go b/firewall/cc.go index a64e645..3b55b34 100644 --- a/firewall/cc.go +++ b/firewall/cc.go @@ -110,15 +110,10 @@ func GetCCPolicyRespByAppID(appID int64) (*models.CCPolicy, error) { // IsCCAttack to judge a request is CC attack, return IsCC, CCPolicy, ClientID, NeedLog func IsCCAttack(r *http.Request, app *models.Application, srcIP string) (bool, *models.CCPolicy, string, bool) { - isCC := false ccPolicy := GetCCPolicyByAppID(app.ID) - if !ccPolicy.IsEnabled { + if !ccPolicy.IsEnabled || ccPolicy.Action == models.Action_Pass_400 { return false, nil, "", false } - if isCC { - clientID := data.SHA256Hash(srcIP) - return isCC, ccPolicy, clientID, false - } ccAppID := app.ID if ccPolicy.AppID == 0 { ccAppID = 0 // Important: stat within general policy diff --git a/gateway/gateway.go b/gateway/gateway.go index 09c7255..4f6d8bf 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -186,6 +186,8 @@ func ReverseHandlerFunc(w http.ResponseWriter, r *http.Request) { captchaURL := CaptchaEntrance + "?id=" + hitInfo.ClientID http.Redirect(w, r, captchaURL, http.StatusFound) return + default: + // models.Action_Pass_400 do nothing } } }