MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / validateSlideForm

Method validateSlideForm

internal/waf/captcha_validator.go:716–757  ·  view source on GitHub ↗
(actionConfig *CaptchaAction, policyId int64, groupId int64, setId int64, originURL string, req requests.Request, writer http.ResponseWriter, useLocalFirewall bool)

Source from the content-addressed store, hash-verified

714}
715
716func (this *CaptchaValidator) validateSlideForm(actionConfig *CaptchaAction, policyId int64, groupId int64, setId int64, originURL string, req requests.Request, writer http.ResponseWriter, useLocalFirewall bool) (allow bool) {
717 var captchaId = req.WAFRaw().FormValue(captchaIdName)
718 var nonce = req.WAFRaw().FormValue("nonce")
719 if len(captchaId) > 0 {
720 var key = "WAF_CAPTCHA:" + captchaId
721 var cacheItem = ttlcache.SharedInt64Cache.Read(key)
722 ttlcache.SharedInt64Cache.Delete(key)
723 if cacheItem != nil {
724 // 清除计数
725 CaptchaDeleteCacheKey(req)
726
727 if cacheItem.Value == types.Int64(nonce) {
728 var life = CaptchaSeconds
729 if actionConfig.Life > 0 {
730 life = types.Int(actionConfig.Life)
731 }
732
733 // 加入到白名单
734 SharedIPWhiteList.RecordIP(wafutils.ComposeIPType(setId, req), actionConfig.Scope, req.WAFServerId(), req.WAFRemoteIP(), time.Now().Unix()+int64(life), policyId, false, groupId, setId, "")
735
736 req.ProcessResponseHeaders(writer.Header(), http.StatusSeeOther)
737
738 // 记录到Cookie
739 this.setCookie(writer, setId, life)
740
741 http.Redirect(writer, req.WAFRaw(), originURL, http.StatusSeeOther)
742
743 return false
744 }
745 } else {
746 // 增加计数
747 if !CaptchaIncreaseFails(req, actionConfig, policyId, groupId, setId, CaptchaPageCodeSubmit, useLocalFirewall) {
748 return false
749 }
750
751 req.ProcessResponseHeaders(writer.Header(), http.StatusSeeOther)
752 http.Redirect(writer, req.WAFRaw(), req.WAFRaw().URL.String(), http.StatusSeeOther)
753 }
754 }
755
756 return true
757}
758
759func (this *CaptchaValidator) validateGeeTestForm(actionConfig *CaptchaAction, policyId int64, groupId int64, setId int64, originURL string, req requests.Request, writer http.ResponseWriter, useLocalFirewall bool) (allow bool) {
760 var geeTestConfig = actionConfig.GeeTestConfig

Callers 1

RunMethod · 0.95

Calls 14

setCookieMethod · 0.95
CaptchaDeleteCacheKeyFunction · 0.85
CaptchaIncreaseFailsFunction · 0.85
RecordIPMethod · 0.80
UnixMethod · 0.80
RedirectMethod · 0.80
WAFRawMethod · 0.65
ReadMethod · 0.65
DeleteMethod · 0.65
WAFServerIdMethod · 0.65
WAFRemoteIPMethod · 0.65

Tested by

no test coverage detected