From 47f06b379e18ea85f9ca59f1a0c5564ceb2e03dd Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sat, 20 Jan 2024 16:18:07 +0800 Subject: [PATCH] =?UTF-8?q?WAF=E7=AD=96=E7=95=A5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=A1=B5=E9=9D=A2=E5=8A=A8=E4=BD=9C=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/waf/action_page.go | 14 ++++++++++++-- internal/waf/waf.go | 1 + internal/waf/waf_manager.go | 8 ++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/internal/waf/action_page.go b/internal/waf/action_page.go index 1b758f9..02fd024 100644 --- a/internal/waf/action_page.go +++ b/internal/waf/action_page.go @@ -10,11 +10,21 @@ import ( type PageAction struct { BaseAction - Status int `yaml:"status" json:"status"` - Body string `yaml:"body" json:"body"` + UseDefault bool `yaml:"useDefault" json:"useDefault"` + Status int `yaml:"status" json:"status"` + Body string `yaml:"body" json:"body"` } func (this *PageAction) Init(waf *WAF) error { + if waf.DefaultPageAction != nil { + if this.Status <= 0 || this.UseDefault { + this.Status = waf.DefaultPageAction.Status + } + if len(this.Body) == 0 || this.UseDefault { + this.Body = waf.DefaultPageAction.Body + } + } + if this.Status <= 0 { this.Status = http.StatusForbidden } diff --git a/internal/waf/waf.go b/internal/waf/waf.go index e5c537c..6d98f5d 100644 --- a/internal/waf/waf.go +++ b/internal/waf/waf.go @@ -27,6 +27,7 @@ type WAF struct { SYNFlood *firewallconfigs.SYNFloodConfig `yaml:"synFlood" json:"synFlood"` DefaultBlockAction *BlockAction + DefaultPageAction *PageAction DefaultCaptchaAction *CaptchaAction hasInboundRules bool diff --git a/internal/waf/waf_manager.go b/internal/waf/waf_manager.go index 1531ce9..b8d4a57 100644 --- a/internal/waf/waf_manager.go +++ b/internal/waf/waf_manager.go @@ -184,6 +184,14 @@ func (this *WAFManager) ConvertWAF(policy *firewallconfigs.HTTPFirewallPolicy) ( } } + // page action + if policy.PageOptions != nil { + w.DefaultPageAction = &PageAction{ + Status: policy.PageOptions.Status, + Body: policy.PageOptions.Body, + } + } + // captcha action if policy.CaptchaOptions != nil { w.DefaultCaptchaAction = &CaptchaAction{