MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / checkWAFRemoteAddr

Method checkWAFRemoteAddr

internal/nodes/http_request_waf.go:122–194  ·  view source on GitHub ↗

check client remote address

(firewallPolicy *firewallconfigs.HTTPFirewallPolicy)

Source from the content-addressed store, hash-verified

120
121// check client remote address
122func (this *HTTPRequest) checkWAFRemoteAddr(firewallPolicy *firewallconfigs.HTTPFirewallPolicy) (blocked bool, breakChecking bool) {
123 if firewallPolicy == nil {
124 return
125 }
126
127 var isDefendMode = firewallPolicy.Mode == firewallconfigs.FirewallModeDefend
128
129 // 检查IP白名单
130 var remoteAddrs []string
131 if len(this.remoteAddr) > 0 {
132 remoteAddrs = []string{this.remoteAddr}
133 } else {
134 remoteAddrs = this.requestRemoteAddrs()
135 }
136
137 var inbound = firewallPolicy.Inbound
138 if inbound == nil {
139 return
140 }
141 for _, ref := range inbound.AllAllowListRefs() {
142 if ref.IsOn && ref.ListId > 0 {
143 var list = iplibrary.SharedIPListManager.FindList(ref.ListId)
144 if list != nil {
145 _, found := list.ContainsIPStrings(remoteAddrs)
146 if found {
147 breakChecking = true
148 return
149 }
150 }
151 }
152 }
153
154 // 检查IP黑名单
155 if isDefendMode {
156 for _, ref := range inbound.AllDenyListRefs() {
157 if ref.IsOn && ref.ListId > 0 {
158 var list = iplibrary.SharedIPListManager.FindList(ref.ListId)
159 if list != nil {
160 item, found := list.ContainsIPStrings(remoteAddrs)
161 if found {
162 // 触发事件
163 if item != nil && len(item.EventLevel) > 0 {
164 actions := iplibrary.SharedActionManager.FindEventActions(item.EventLevel)
165 for _, action := range actions {
166 goNext, err := action.DoHTTP(this.RawReq, this.RawWriter)
167 if err != nil {
168 remotelogs.Error("HTTP_REQUEST_WAF", "do action '"+err.Error()+"' failed: "+err.Error())
169 return true, false
170 }
171 if !goNext {
172 this.disableLog = true
173 return true, false
174 }
175 }
176 }
177
178 // TODO 考虑是否需要记录日志信息吗,可能数据量非常庞大,所以暂时不记录
179

Callers 1

doWAFRequestMethod · 0.95

Calls 9

requestRemoteAddrsMethod · 0.95
ErrorFunction · 0.92
FindListMethod · 0.80
ContainsIPStringsMethod · 0.80
FindEventActionsMethod · 0.80
DoHTTPMethod · 0.65
WriteHeaderMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected