/
request_waf.go
52 lines (44 loc) · 1.05 KB
/
request_waf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package teaproxy
import (
"github.com/TeaWeb/code/teawaf/actions"
"github.com/iwind/TeaGo/logs"
"net/http"
)
// call request waf
func (this *Request) callWAFRequest(writer *ResponseWriter) (blocked bool) {
if this.waf == nil {
return
}
goNext, ruleSet, err := this.waf.MatchRequest(this.raw, writer)
if err != nil {
logs.Error(err)
return
}
if ruleSet != nil {
if ruleSet.Action != actions.ActionAllow {
this.SetAttr("waf.action", ruleSet.Action)
this.SetAttr("waf.ruleset", ruleSet.Name)
this.SetAttr("waf.id", this.waf.Id)
}
}
return !goNext
}
// call response waf
func (this *Request) callWAFResponse(resp *http.Response, writer *ResponseWriter) (blocked bool) {
if this.waf == nil {
return
}
goNext, ruleSet, err := this.waf.MatchResponse(this.raw, resp, writer)
if err != nil {
logs.Error(err)
return
}
if ruleSet != nil {
if ruleSet.Action != actions.ActionAllow {
this.SetAttr("waf.action", ruleSet.Action)
this.SetAttr("waf.ruleset", ruleSet.Name)
this.SetAttr("waf.id", this.waf.Id)
}
}
return !goNext
}