人机识别验证成功后记录到Cookie,以便于在重启、切换节点时仍能恢复验证状态

This commit is contained in:
刘祥超
2024-04-11 16:14:14 +08:00
parent b1151479e0
commit dc9cff541e
4 changed files with 136 additions and 0 deletions

View File

@@ -4,8 +4,10 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
wafutils "github.com/TeaOSLab/EdgeNode/internal/waf/utils"
"github.com/iwind/TeaGo/types"
"net/http"
"net/url"
"strings"
@@ -130,6 +132,22 @@ func (this *CaptchaAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, req
}
}
// 检查Cookie值
var fullCookieName = captchaCookiePrefix + "_" + types.String(set.Id)
cookie, err := req.WAFRaw().Cookie(fullCookieName)
if err == nil && cookie != nil && len(cookie.Value) > 0 {
var info = &AllowCookieInfo{}
err = info.Decode(cookie.Value)
if err == nil && set.Id == info.SetId && info.ExpiresAt > fasttime.Now().Unix() {
// 重新记录到白名单
SharedIPWhiteList.RecordIP(wafutils.ComposeIPType(set.Id, req), this.Scope, req.WAFServerId(), req.WAFRemoteIP(), info.ExpiresAt, waf.Id, false, group.Id, set.Id, "")
return PerformResult{
ContinueRequest: true,
}
}
}
var refURL = req.WAFRaw().URL.String()
// 覆盖配置