优化WAF动作“显示网页”显示

This commit is contained in:
刘祥超
2023-12-09 15:55:40 +08:00
parent 05881b457d
commit ee2565905e

View File

@@ -39,7 +39,23 @@ func (this *PageAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, reques
request.ProcessResponseHeaders(writer.Header(), this.Status)
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
writer.WriteHeader(this.Status)
_, _ = writer.Write([]byte(request.Format(this.Body)))
var body = this.Body
if len(body) == 0 {
body = `<!DOCTYPE html>
<html lang="en">
<title>403 Forbidden</title>
<style>
address { line-height: 1.8; }
</style>
<body>
<h1>403 Forbidden By WAF</h1>
<address>Connection: ${remoteAddr} (Client) -&gt; ${serverAddr} (Server)</address>
<address>Request ID: ${requestId}</address>
</body>
</html>`
}
_, _ = writer.Write([]byte(request.Format(body)))
return false, false
}