Skip to content

Commit 9f86c29

Browse files
committed
lib/anubis: do not apply bot rules if address check fails
Closes #83
1 parent b112435 commit 9f86c29

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

docs/docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Fixed and clarified installation instructions
1515
- Introduced integration tests using Playwright
1616
- Refactor & Split up Anubis into cmd and lib.go
17+
- Fixed bot check to only apply if address range matches
1718

1819
## v1.14.2
1920

lib/anubis.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,13 @@ func (s *Server) check(r *http.Request) (CheckResult, *policy.Bot, error) {
478478

479479
for _, b := range s.policy.Bots {
480480
if b.UserAgent != nil {
481-
if uaMatch := b.UserAgent.MatchString(r.UserAgent()); uaMatch || (uaMatch && s.checkRemoteAddress(b, addr)) {
481+
if b.UserAgent.MatchString(r.UserAgent()) && s.checkRemoteAddress(b, addr) {
482482
return cr("bot/"+b.Name, b.Action), &b, nil
483483
}
484484
}
485485

486486
if b.Path != nil {
487-
if pathMatch := b.Path.MatchString(r.URL.Path); pathMatch || (pathMatch && s.checkRemoteAddress(b, addr)) {
487+
if b.Path.MatchString(r.URL.Path) && s.checkRemoteAddress(b, addr) {
488488
return cr("bot/"+b.Name, b.Action), &b, nil
489489
}
490490
}
@@ -507,7 +507,7 @@ func (s *Server) check(r *http.Request) (CheckResult, *policy.Bot, error) {
507507

508508
func (s *Server) checkRemoteAddress(b policy.Bot, addr net.IP) bool {
509509
if b.Ranger == nil {
510-
return false
510+
return true
511511
}
512512

513513
ok, err := b.Ranger.Contains(addr)

0 commit comments

Comments
 (0)