block more user-agents.

This commit is contained in:
fiatjaf
2024-09-26 10:17:28 -03:00
parent a252707ab5
commit 567fdbb619
2 changed files with 28 additions and 3 deletions

View File

@@ -11,9 +11,18 @@ import (
func agentBlock(next http.HandlerFunc) http.HandlerFunc { func agentBlock(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ua := r.Header.Get("User-Agent") ua := r.Header.Get("User-Agent")
for _, bua := range []string{"Amazonbot", "semrush", "Bytespider", "AhrefsBot"} { for _, bua := range []string{
"Amazonbot",
"semrush",
"Bytespider",
"AhrefsBot",
"DataForSeoBot",
"Yandex",
"meta-externalagent",
"DotBot",
} {
if strings.Contains(ua, bua) { if strings.Contains(ua, bua) {
log.Debug().Str("ua", ua).Msg("user-agent blocked") // log.Debug().Str("ua", ua).Msg("user-agent blocked")
http.Error(w, "Forbidden", http.StatusForbidden) http.Error(w, "Forbidden", http.StatusForbidden)
return return
} }

View File

@@ -7,7 +7,23 @@ import (
func renderRobots(w http.ResponseWriter, r *http.Request) { func renderRobots(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=3600") w.Header().Set("Cache-Control", "max-age=3600")
fmt.Fprintf(w, `User-agent: * fmt.Fprintf(w, `
User-agent: Amazonbot
Disallow: /
User-agent: SemrushBot
Disallow: /
User-agent: meta-externalagent
Disallow: /
User-agent: DataForSeoBot
Disallow: /
User-agent: dotbot
Disallow: /
User-agent: *
Allow: / Allow: /
Sitemap: https://%s/npubs-archive.xml Sitemap: https://%s/npubs-archive.xml