From 107e8c3e2f8636e53671e76d18ee81cc19a08b53 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 10 Aug 2023 10:31:38 +0800 Subject: [PATCH] =?UTF-8?q?WAF=E7=AD=96=E7=95=A5=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E9=BB=98=E8=AE=A4=E7=9A=84=E5=8C=BA?= =?UTF-8?q?=E5=9F=9F/=E7=9C=81=E4=BB=BD=E5=B0=81=E7=A6=81=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_waf.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/nodes/http_request_waf.go b/internal/nodes/http_request_waf.go index c5eba0d..4611de8 100644 --- a/internal/nodes/http_request_waf.go +++ b/internal/nodes/http_request_waf.go @@ -174,8 +174,15 @@ func (this *HTTPRequest) checkWAFRequest(firewallPolicy *firewallconfigs.HTTPFir if !regionConfig.IsAllowedCountry(result.CountryId(), result.ProvinceId()) { this.firewallPolicyId = firewallPolicy.Id + var promptHTML string if len(regionConfig.CountryHTML) > 0 { - var formattedHTML = this.Format(regionConfig.CountryHTML) + promptHTML = regionConfig.CountryHTML + } else if this.ReqServer != nil && this.ReqServer.HTTPFirewallPolicy != nil && len(this.ReqServer.HTTPFirewallPolicy.DenyCountryHTML) > 0 { + promptHTML = this.ReqServer.HTTPFirewallPolicy.DenyCountryHTML + } + + if len(promptHTML) > 0 { + var formattedHTML = this.Format(promptHTML) this.writer.Header().Set("Content-Type", "text/html; charset=utf-8") this.writer.Header().Set("Content-Length", types.String(len(formattedHTML))) this.writer.WriteHeader(http.StatusForbidden) @@ -203,8 +210,15 @@ func (this *HTTPRequest) checkWAFRequest(firewallPolicy *firewallconfigs.HTTPFir if !regionConfig.IsAllowedProvince(result.CountryId(), result.ProvinceId()) { this.firewallPolicyId = firewallPolicy.Id + var promptHTML string if len(regionConfig.ProvinceHTML) > 0 { - var formattedHTML = this.Format(regionConfig.ProvinceHTML) + promptHTML = regionConfig.ProvinceHTML + } else if this.ReqServer != nil && this.ReqServer.HTTPFirewallPolicy != nil && len(this.ReqServer.HTTPFirewallPolicy.DenyProvinceHTML) > 0 { + promptHTML = this.ReqServer.HTTPFirewallPolicy.DenyProvinceHTML + } + + if len(promptHTML) > 0 { + var formattedHTML = this.Format(promptHTML) this.writer.Header().Set("Content-Type", "text/html; charset=utf-8") this.writer.Header().Set("Content-Length", types.String(len(formattedHTML))) this.writer.WriteHeader(http.StatusForbidden)