-
-
Notifications
You must be signed in to change notification settings - Fork 296
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
Open
JasonLovesDoggo
wants to merge
8
commits into
TecharoHQ:main
Choose a base branch
from
JasonLovesDoggo:feature/tarpit-express
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b205c44
feat: implement DENY_AND_REROUTE action with URL validation and redir…
JasonLovesDoggo d059b0b
docs: add semi-shitpost quote to robots2policy documentation
JasonLovesDoggo c092c0b
feat: add DENY_AND_REROUTE action for redirecting denied requests to …
JasonLovesDoggo 80c8483
docs: add usage examples for DENY_AND_REROUTE action in policies docu…
JasonLovesDoggo fcdec8c
docs: update policies documentation for DENY_AND_REROUTE action and a…
JasonLovesDoggo 96e4df6
Update metadata
JasonLovesDoggo 19f7a74
Merge branch 'main' into feature/tarpit-express
JasonLovesDoggo 7146a80
Merge branch 'main' into feature/tarpit-express
JasonLovesDoggo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,6 +231,17 @@ func (s *Server) checkRules(w http.ResponseWriter, r *http.Request, cr policy.Ch | |
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) | ||
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: | ||
|
@@ -432,6 +443,15 @@ func cr(name string, rule config.Rule, weight int) policy.CheckResult { | |
} | ||
} | ||
|
||
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) (policy.CheckResult, *policy.Bot, error) { | ||
host := r.Header.Get("X-Real-Ip") | ||
|
@@ -456,6 +476,8 @@ func (s *Server) check(r *http.Request) (policy.CheckResult, *policy.Bot, error) | |
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: | ||
slog.Debug("adjusting weight", "name", b.Name, "delta", b.Weight.Adjust) | ||
weight += b.Weight.Adjust | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.