diff options
| author | Neur0toxine <pashok9825@gmail.com> | 2025-04-21 01:18:21 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-20 22:18:21 +0000 |
| commit | 7dc545cfa9281efcf802ff0afd6d3796c4f5922c (patch) | |
| tree | 15bb4fbb17df640bb1d4860d5dcb0864488dcd73 /lib/anubis.go | |
| parent | 1add24b907f35e645190078045867369f34919c2 (diff) | |
| download | anubis-7dc545cfa9281efcf802ff0afd6d3796c4f5922c.tar.xz anubis-7dc545cfa9281efcf802ff0afd6d3796c4f5922c.zip | |
Add headers bot rule (#300)
* Closes #291: add headers support to bot policy rules
* Fix config validator
Diffstat (limited to 'lib/anubis.go')
| -rw-r--r-- | lib/anubis.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/anubis.go b/lib/anubis.go index 353fe63..ba143f9 100644 --- a/lib/anubis.go +++ b/lib/anubis.go @@ -548,6 +548,12 @@ func (s *Server) check(r *http.Request) (CheckResult, *policy.Bot, error) { return cr("bot/"+b.Name, b.Action), &b, nil } } + + if len(b.Headers) > 0 { + if s.checkHeaders(b, r.Header) { + return cr("bot/"+b.Name, b.Action), &b, nil + } + } } return cr("default/allow", config.RuleAllow), &policy.Bot{ @@ -572,6 +578,27 @@ func (s *Server) checkRemoteAddress(b policy.Bot, addr net.IP) bool { return ok } +func (s *Server) checkHeaders(b policy.Bot, header http.Header) bool { + if len(b.Headers) == 0 { + return true + } + + for name, expr := range b.Headers { + values := header.Values(name) + if values == nil { + return false + } + + for _, value := range values { + if !expr.MatchString(value) { + return false + } + } + } + + return true +} + func (s *Server) CleanupDecayMap() { s.DNSBLCache.Cleanup() s.OGTags.Cleanup() |
