feat(botfilter): matcher.go part 1/5
This commit is contained in:
1 parent
1dedeab625
commit
40d90db556
1 file changed
+19
+19
@@ -15,3 +15,22 @@ func inspectRequest(r *http.Request, cfg *compiledConfig) matchResult {
|
||||
paths := requestPaths(r)
|
||||
userAgent := strings.TrimSpace(r.UserAgent())
|
||||
|
||||
if cfg.RequireUserAgent && userAgent == "" {
|
||||
return matchResult{points: cfg.EmptyUserAgentScore, forceBan: true, reason: "missing user-agent"}
|
||||
}
|
||||
if cfg.RequireAccept && !hasHeader(r, "Accept") {
|
||||
return matchResult{points: cfg.MissingAcceptScore, forceBan: true, reason: "missing accept"}
|
||||
}
|
||||
if cfg.RequireHost && strings.TrimSpace(r.Host) == "" {
|
||||
return matchResult{forceBan: true, reason: "missing host"}
|
||||
}
|
||||
if containsToken(strings.ToLower(userAgent), cfg.blockedAgents) {
|
||||
return matchResult{points: cfg.BlockedUserAgentScore, forceBan: true, reason: "blocked user-agent"}
|
||||
}
|
||||
if matchesBlockedPath(paths, cfg.blockedPaths) {
|
||||
return matchResult{points: cfg.BadPathScore, forceBan: true, reason: "blocked path"}
|
||||
}
|
||||
if matchesBlockedExtension(paths, cfg.blockedExts) {
|
||||
return matchResult{points: cfg.BadPathScore, forceBan: true, reason: "blocked extension"}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user