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

Method checkWAFResponse

internal/nodes/http_request_waf.go:394–445  ·  view source on GitHub ↗

check waf outbound rules

(firewallPolicy *firewallconfigs.HTTPFirewallPolicy, resp *http.Response, forceLog bool, logRequestBody bool, ignoreRules bool)

Source from the content-addressed store, hash-verified

392
393// check waf outbound rules
394func (this *HTTPRequest) checkWAFResponse(firewallPolicy *firewallconfigs.HTTPFirewallPolicy, resp *http.Response, forceLog bool, logRequestBody bool, ignoreRules bool) (blocked bool, breakChecking bool) {
395 if firewallPolicy == nil || !firewallPolicy.IsOn || !firewallPolicy.Outbound.IsOn || firewallPolicy.Mode == firewallconfigs.FirewallModeBypass {
396 return
397 }
398
399 // 是否执行规则
400 if ignoreRules {
401 return
402 }
403
404 var w = waf.SharedWAFManager.FindWAF(firewallPolicy.Id)
405 if w == nil {
406 return
407 }
408
409 result, err := w.MatchResponse(this, resp, this.writer)
410 if err != nil {
411 if !this.canIgnore(err) {
412 remotelogs.Warn("HTTP_REQUEST_WAF", this.rawURI+": "+err.Error())
413 }
414 return
415 }
416 if result.IsAllowed && (len(result.AllowScope) == 0 || result.AllowScope == waf.AllowScopeGlobal) {
417 breakChecking = true
418 }
419 if forceLog && logRequestBody && result.HasRequestBody && result.Set != nil && result.Set.HasAttackActions() {
420 this.wafHasRequestBody = true
421 }
422
423 if result.Set != nil {
424 if forceLog {
425 this.forceLog = true
426 }
427
428 if result.Set.HasSpecialActions() {
429 this.firewallPolicyId = firewallPolicy.Id
430 this.firewallRuleGroupId = types.Int64(result.Group.Id)
431 this.firewallRuleSetId = types.Int64(result.Set.Id)
432
433 if result.Set.HasAttackActions() {
434 this.isAttack = true
435 }
436
437 // 添加统计
438 stats.SharedHTTPRequestStatManager.AddFirewallRuleGroupId(this.ReqServer.Id, this.firewallRuleGroupId, result.Set.Actions)
439 }
440
441 this.firewallActions = append(result.Set.ActionCodes(), firewallPolicy.Mode)
442 }
443
444 return !result.GoNext, breakChecking
445}
446
447// WAFRaw 原始请求
448func (this *HTTPRequest) WAFRaw() *http.Request {

Callers 1

doWAFResponseMethod · 0.95

Calls 9

canIgnoreMethod · 0.95
WarnFunction · 0.92
FindWAFMethod · 0.80
HasAttackActionsMethod · 0.80
HasSpecialActionsMethod · 0.80
ActionCodesMethod · 0.80
MatchResponseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected