Browse Source

wip:js加密过滤白名单

wangkaiyue 1 năm trước cách đây
mục cha
commit
16b2e23046

+ 13 - 13
core/proxy/filterPoly/filterPoly.go

@@ -20,18 +20,18 @@ return
 statusCode:0通过 -1黑名单 1被拦截 2出现验证码
 key
 */
-func (a *ReqFilterPoly) IdFilter(ctx g.Ctx, id string) (statusCode int, key string) {
+func (a *ReqFilterPoly) IdFilter(ctx g.Ctx, id string) (statusCode int, key string, inWhite bool) {
 	//是否开启白名单(开启白名单且在白名单中直接跳过)
 	if a.Rule.CheckWhite && a.checkWhiteList(id) {
-		return 0, id
+		return 0, id, true
 	}
 	//检测是否在黑名单中
 	if a.Rule.CheckBlack && a.checkBackList(id) {
-		return -1, id
+		return -1, id, false
 	}
 	//检测是否处于验证码校验状态
 	if a.IsWaitVerify(id) {
-		return 2, id
+		return 2, id, false
 	}
 
 	// 阈值校验
@@ -58,9 +58,9 @@ func (a *ReqFilterPoly) IdFilter(ctx g.Ctx, id string) (statusCode int, key stri
 		log.WithContext(ctx).Infof("%s 超出最大请求限制,加入临时黑名单", id)
 		a.addBackList(id, "exceed IdMax")
 		AllRedis.Del(fmt.Sprintf(RateDataKey, a.Rule.Alias, a.Rule.IdMax[0], id))
-		return -1, id
+		return -1, id, false
 	}
-	return statusCode, id
+	return statusCode, id, false
 }
 
 /*
@@ -70,22 +70,22 @@ ip:请求ip地址
 return
 statusCode:0通过 -1黑名单 1被拦截 2出现验证码
 */
-func (a *ReqFilterPoly) IpFilter(ctx g.Ctx, ip string) (statusCode int, key string) {
+func (a *ReqFilterPoly) IpFilter(ctx g.Ctx, ip string) (statusCode int, key string, inWhite bool) {
 	if !a.Rule.BCheckIp {
-		return 0, ip
+		return 0, ip, false
 	}
 	//是否开启白名单(开启白名单且在白名单中直接跳过)
 	if a.Rule.CheckWhite && a.checkWhiteList(ip) {
-		return 0, ip
+		return 0, ip, true
 	}
 	//检测是否在黑名单中
 	if a.Rule.CheckBlack && a.checkBackList(ip) {
-		return -1, ip
+		return -1, ip, false
 	}
 
 	//检测是否处于验证码校验状态
 	if a.IsWaitVerify(ip) {
-		return 2, ip
+		return 2, ip, false
 	}
 
 	for i, v := range a.Rule.IpThreshold {
@@ -108,7 +108,7 @@ func (a *ReqFilterPoly) IpFilter(ctx g.Ctx, ip string) (statusCode int, key stri
 		log.WithContext(ctx).Infof("%s 超出最大请求限制,加入临时黑名单", ip)
 		a.addBackList(ip, "exceed IdMax")
 		AllRedis.Del(fmt.Sprintf(RateDataKey, a.Rule.Alias, a.Rule.IpMax[0], ip))
-		return -1, ip
+		return -1, ip, false
 	}
-	return statusCode, ip
+	return statusCode, ip, false
 }

+ 2 - 2
core/proxy/middleware/spiderPolyHandler.go

@@ -39,7 +39,7 @@ func FilterPolyHandler(r *ghttp.Request) {
 		gCtx := router.GetGContext(ctx)
 		//获取策略
 		poly := filterPolyManager.GetRule(gCtx.RouterRule.LimitPloy)
-		status, key := func() (int, string) {
+		status, key, inWhite := func() (int, string, bool) {
 			//用户身份切换
 			userFlag, _ := common.If(gCtx.Sess.MgoUserId != "", gCtx.Sess.MgoUserId, gCtx.Sess.UserId).(string)
 			if gCtx.Sess.UserId != "" && poly.Rule.BCheckId { //id请求频率校验
@@ -70,7 +70,7 @@ func FilterPolyHandler(r *ghttp.Request) {
 			return
 		}
 		//处理相应内容加
-		if poly.Rule.JsEncrypt == 1 {
+		if !inWhite && poly.Rule.JsEncrypt == 1 {
 			if !returnHtml {
 				r.SetCtxVar("changeFunc", SpiderJsEncrypt)
 			}