feat(botfilter): add clientCache.behaviorScoreLocked
This commit is contained in:
1 parent
70f6339cee
commit
e4294c7af1
1 file changed
+26
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user