check waf outbound rules
(firewallPolicy *firewallconfigs.HTTPFirewallPolicy, resp *http.Response, forceLog bool, logRequestBody bool, ignoreRules bool)
| 392 | |
| 393 | // check waf outbound rules |
| 394 | func (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 原始请求 |
| 448 | func (this *HTTPRequest) WAFRaw() *http.Request { |
no test coverage detected