Add headers bot rule (#300)
* Closes #291: add headers support to bot policy rules * Fix config validator
This commit is contained in:
parent
1add24b907
commit
7dc545cfa9
9 changed files with 125 additions and 21 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue