MCPcopy Create free account
hub / github.com/crowdsecurity/crowdsec / CheckIPsWL

Method CheckIPsWL

pkg/parser/whitelist.go:42–74  ·  view source on GitHub ↗
(p *pipeline.Event)

Source from the content-addressed store, hash-verified

40}
41
42func (n *Node) CheckIPsWL(p *pipeline.Event) bool {
43 srcs := p.ParseIPSources()
44 isWhitelisted := false
45 if !n.ContainsIPLists() {
46 return isWhitelisted
47 }
48 n.bumpWhitelistMetric(metrics.NodesWlHits, p)
49 for _, src := range srcs {
50 if isWhitelisted {
51 break
52 }
53 for _, v := range n.Whitelist.B_Ips {
54 if v == src {
55 n.Logger.Debugf("Event from [%s] is whitelisted by IP (%s), reason [%s]", src, v, n.Whitelist.Reason)
56 isWhitelisted = true
57 break
58 }
59 n.Logger.Tracef("whitelist: %s is not eq [%s]", src, v)
60 }
61 for _, v := range n.Whitelist.B_Cidrs {
62 if v.Contains(src) {
63 n.Logger.Debugf("Event from [%s] is whitelisted by CIDR (%s), reason [%s]", src, v, n.Whitelist.Reason)
64 isWhitelisted = true
65 break
66 }
67 n.Logger.Tracef("whitelist: %s not in [%s]", src, v)
68 }
69 }
70 if isWhitelisted {
71 n.bumpWhitelistMetric(metrics.NodesWlHitsOk, p)
72 }
73 return isWhitelisted
74}
75
76func (n *Node) CheckExprWL(cachedExprEnv map[string]any, p *pipeline.Event) (bool, error) {
77 isWhitelisted := false

Callers 2

TestWhitelistCheckFunction · 0.95
processWhitelistMethod · 0.95

Calls 4

ContainsIPListsMethod · 0.95
bumpWhitelistMetricMethod · 0.95
ParseIPSourcesMethod · 0.80
TracefMethod · 0.80

Tested by 1

TestWhitelistCheckFunction · 0.76