-
-
Notifications
You must be signed in to change notification settings - Fork 393
feat: implement a DENY_AND_REROUTE action to redirect to tarpits #705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b205c44
d059b0b
c092c0b
80c8483
fcdec8c
96e4df6
19f7a74
7146a80
71bdd6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -275,6 +275,17 @@ | |
| lg.Debug("rule hash", "hash", hash) | ||
| s.respondWithStatus(w, r, fmt.Sprintf("%s %s", localizer.T("access_denied"), hash), s.policy.StatusCodes.Deny) | ||
| return true | ||
| case config.RuleDenyAndReroute: | ||
| s.ClearCookie(w, s.cookieName, cookiePath) | ||
|
Check failure on line 279 in lib/anubis.go
|
||
| lg.Info("deny and reroute", "reroute_to", cr.RerouteTo) | ||
| if cr.RerouteTo == nil || *cr.RerouteTo == "" { | ||
| lg.Error("reroute URL is missing for DENY_AND_REROUTE action") | ||
| s.respondWithError(w, r, "Internal Server Error: administrator has misconfigured Anubis. Please contact the administrator and ask them to look for the logs around \"maybeReverseProxy.RuleDenyAndReroute\"") | ||
| return true | ||
| } | ||
| // note for others, would it be better to be reverse proxying here? | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just had some concerns related to anubis performance + how constantly the scrapers would end up this path |
||
| http.Redirect(w, r, *cr.RerouteTo, http.StatusTemporaryRedirect) | ||
| return true | ||
| case config.RuleChallenge: | ||
| lg.Debug("challenge requested") | ||
| case config.RuleBenchmark: | ||
|
|
@@ -553,6 +564,15 @@ | |
| } | ||
| } | ||
|
|
||
| func crWithReroute(name string, rule config.Rule, weight int, rerouteTo *string) policy.CheckResult { | ||
| return policy.CheckResult{ | ||
| Name: name, | ||
| Rule: rule, | ||
| Weight: weight, | ||
| RerouteTo: rerouteTo, | ||
| } | ||
| } | ||
|
|
||
| // Check evaluates the list of rules, and returns the result | ||
| func (s *Server) check(r *http.Request, lg *slog.Logger) (policy.CheckResult, *policy.Bot, error) { | ||
| host := r.Header.Get("X-Real-Ip") | ||
|
|
@@ -577,6 +597,8 @@ | |
| switch b.Action { | ||
| case config.RuleDeny, config.RuleAllow, config.RuleBenchmark, config.RuleChallenge: | ||
| return cr("bot/"+b.Name, b.Action, weight), &b, nil | ||
| case config.RuleDenyAndReroute: | ||
| return crWithReroute("bot/"+b.Name, b.Action, weight, b.RerouteTo), &b, nil | ||
| case config.RuleWeigh: | ||
| lg.Debug("adjusting weight", "name", b.Name, "delta", b.Weight.Adjust) | ||
| weight += b.Weight.Adjust | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.