From cecaea6256121a2801ef76f78e9fb6d6ab0e253a Mon Sep 17 00:00:00 2001 From: hoelee Date: Wed, 8 Apr 2026 11:12:00 +0800 Subject: [PATCH] feat(botfilter): matcher.go part 1/5 --- matcher.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/matcher.go b/matcher.go index 714bb748..4179e366 100644 --- a/matcher.go +++ b/matcher.go @@ -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"} + } +