-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaction.go
69 lines (60 loc) · 1.49 KB
/
action.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package openrasp
import (
"encoding/json"
"strconv"
"sync"
"github.com/baidu-security/openrasp-golang/common"
"github.com/baidu-security/openrasp-golang/model"
v8 "github.com/baidu-security/openrasp-v8/go"
)
type BuildinAction struct {
actionMap map[common.CheckType]model.InterceptCode
mu sync.RWMutex
}
func NewBuildinAction() *BuildinAction {
return &BuildinAction{
actionMap: make(map[common.CheckType]model.InterceptCode),
}
}
func (ba *BuildinAction) Clear() {
ba.mu.Lock()
defer ba.mu.Unlock()
ba.actionMap = nil
}
func (ba *BuildinAction) Set(ct common.CheckType, ic model.InterceptCode) {
ba.mu.Lock()
defer ba.mu.Unlock()
ba.actionMap[ct] = ic
}
func (ba *BuildinAction) Get(ct common.CheckType) model.InterceptCode {
ba.mu.RLock()
defer ba.mu.RUnlock()
ic, ok := ba.actionMap[ct]
if ok {
return ic
}
return model.Ignore
}
func (ba *BuildinAction) OnPluginUpdate() {
script := common.BuildinActionScript()
if len(script) > 0 {
actionResult := v8.ExecScript(script, "extract_buildin_action")
var ms [][]string
unquotedResult, err := strconv.Unquote(actionResult)
if err != nil {
return
}
err = json.Unmarshal([]byte(unquotedResult), &ms)
if err == nil {
for _, stringPair := range ms {
if len(stringPair) == 2 {
ba.Set(common.CheckStringToType(stringPair[0]), model.InterceptStringToCode(stringPair[1]))
}
}
}
}
}
func IgnoreActionOption(ac common.AttackChecker) bool {
ic := GetAction().Get(ac.GetType())
return ic == model.Ignore
}