| 248 | } |
| 249 | |
| 250 | func (this *WAF) MatchRequest(req requests.Request, writer http.ResponseWriter, defaultCaptchaType firewallconfigs.ServerCaptchaType) (result MatchResult, err error) { |
| 251 | if !this.hasInboundRules { |
| 252 | return MatchResult{ |
| 253 | GoNext: true, |
| 254 | }, nil |
| 255 | } |
| 256 | |
| 257 | // validate captcha |
| 258 | var rawPath = req.WAFRaw().URL.Path |
| 259 | if rawPath == CaptchaPath { |
| 260 | req.DisableAccessLog() |
| 261 | req.DisableStat() |
| 262 | captchaValidator.Run(req, writer, defaultCaptchaType) |
| 263 | return |
| 264 | } |
| 265 | |
| 266 | // Get 302验证 |
| 267 | if rawPath == Get302Path { |
| 268 | req.DisableAccessLog() |
| 269 | req.DisableStat() |
| 270 | get302Validator.Run(req, writer) |
| 271 | return |
| 272 | } |
| 273 | |
| 274 | // match rules |
| 275 | var hasRequestBody bool |
| 276 | for _, group := range this.Inbound { |
| 277 | if !group.IsOn { |
| 278 | continue |
| 279 | } |
| 280 | b, hasCheckedRequestBody, set, matchErr := group.MatchRequest(req) |
| 281 | if hasCheckedRequestBody { |
| 282 | hasRequestBody = true |
| 283 | } |
| 284 | if matchErr != nil { |
| 285 | return MatchResult{ |
| 286 | GoNext: true, |
| 287 | HasRequestBody: hasRequestBody, |
| 288 | }, matchErr |
| 289 | } |
| 290 | if b { |
| 291 | var performResult = set.PerformActions(this, group, req, writer) |
| 292 | if !performResult.GoNextSet { |
| 293 | if performResult.GoNextGroup { |
| 294 | continue |
| 295 | } |
| 296 | return MatchResult{ |
| 297 | GoNext: performResult.ContinueRequest, |
| 298 | HasRequestBody: hasRequestBody, |
| 299 | Group: group, |
| 300 | Set: set, |
| 301 | IsAllowed: performResult.IsAllowed, |
| 302 | AllowScope: performResult.AllowScope, |
| 303 | }, nil |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | return MatchResult{ |