feat(botfilter): add clientCache.behaviorScoreLocked

This commit is contained in:
hoelee committed 2026-02-12 16:04:00 +08:00
1 parent b9f1b8d746
commit a1332aac20
1 file changed
+26
+26
View File
@@ -140,3 +140,29 @@ func (c *clientCache) observeResponse(ip string, status int, points int, now tim
return cacheResult{score: score}
}
func (c *clientCache) behaviorScoreLocked(state *clientState, paths []string) int {
// The heuristic is intentionally weak: visiting a content page first is
// normal for a shared link, so it adds only the configured 15 points.
// It becomes useful in combination with malformed headers or 404 scans.
firstRequest := state.requests == 0
isContent := false
for _, requestPath := range paths {
if requestPath == "/" || requestPath == "/index.html" {
state.sawHome = true
}
if requestPath == "/favicon.ico" {
state.sawFavicon = true
}
if hasStaticAssetExtension(requestPath) {
state.sawStatic = true
}
if pathMatchesAny(requestPath, c.randomPaths) {
isContent = true
}
}
if firstRequest && isContent && !state.sawHome && !state.sawStatic && !state.sawFavicon {
return c.randomScore
}
return 0
}