diff --git a/agentblock.go b/agentblock.go new file mode 100644 index 0000000..5b2ec9d --- /dev/null +++ b/agentblock.go @@ -0,0 +1,20 @@ +package main + +import ( + "net/http" + "strings" +) + +func agentBlock(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + userAgent := r.UserAgent() + if strings.Contains(userAgent, "Amazonbot") { + // Drop the request by returning a 403 Forbidden response + http.Error(w, "Forbidden", http.StatusForbidden) + return + } + + // Call the next handler in the chain + next.ServeHTTP(w, r) + }) +} diff --git a/main.go b/main.go index a0178b3..e56a12f 100644 --- a/main.go +++ b/main.go @@ -159,10 +159,12 @@ func main() { mux.HandleFunc("/{code}", renderEvent) mux.HandleFunc("/{$}", renderHomepage) + loggedMux := loggingMiddleware(mux) + agentMux := agentBlock(loggedMux) corsHandler := cors.Default().Handler( http.HandlerFunc( - ipblock(loggedMux), // Wrap loggedMux with IP blocking + ipblock(agentMux), ), ) go updateCloudflareRangesRoutine()