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

Method validateOneClickForm

internal/waf/captcha_validator.go:513–554  ·  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

511}
512
513func (this *CaptchaValidator) validateOneClickForm(actionConfig *CaptchaAction, policyId int64, groupId int64, setId int64, originURL string, req requests.Request, writer http.ResponseWriter, useLocalFirewall bool) (allow bool) {
514 var captchaId = req.WAFRaw().FormValue(captchaIdName)
515 var nonce = req.WAFRaw().FormValue("nonce")
516 if len(captchaId) > 0 {
517 var key = "WAF_CAPTCHA:" + captchaId
518 var cacheItem = ttlcache.SharedInt64Cache.Read(key)
519 ttlcache.SharedInt64Cache.Delete(key)
520 if cacheItem != nil {
521 // 清除计数
522 CaptchaDeleteCacheKey(req)
523
524 if cacheItem.Value == types.Int64(nonce) {
525 var life = CaptchaSeconds
526 if actionConfig.Life > 0 {
527 life = types.Int(actionConfig.Life)
528 }
529
530 // 加入到白名单
531 SharedIPWhiteList.RecordIP(wafutils.ComposeIPType(setId, req), actionConfig.Scope, req.WAFServerId(), req.WAFRemoteIP(), time.Now().Unix()+int64(life), policyId, false, groupId, setId, "")
532
533 req.ProcessResponseHeaders(writer.Header(), http.StatusSeeOther)
534
535 // 记录到Cookie
536 this.setCookie(writer, setId, life)
537
538 http.Redirect(writer, req.WAFRaw(), originURL, http.StatusSeeOther)
539
540 return false
541 }
542 } else {
543 // 增加计数
544 if !CaptchaIncreaseFails(req, actionConfig, policyId, groupId, setId, CaptchaPageCodeSubmit, useLocalFirewall) {
545 return false
546 }
547
548 req.ProcessResponseHeaders(writer.Header(), http.StatusSeeOther)
549 http.Redirect(writer, req.WAFRaw(), req.WAFRaw().URL.String(), http.StatusSeeOther)
550 }
551 }
552
553 return true
554}
555
556func (this *CaptchaValidator) showSlideForm(actionConfig *CaptchaAction, req requests.Request, writer http.ResponseWriter) {
557 var lang = actionConfig.Lang

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