···515515 fmt.Printf("Now serving at http://%s:%d\n", app.Config.Host, app.Config.Port)
516516 stdLog.Fatal(
517517 http.ListenAndServe(fmt.Sprintf("%s:%d", app.Config.Host, app.Config.Port),
518518- HTTPLog(DefaultHeaders(mux)),
518518+ CheckRequest(&app, HTTPLog(DefaultHeaders(mux))),
519519 ))
520520}
521521···560560 "the love of creating",
561561 "not for the sake of art; not for the sake of money; we like painting naked people",
562562 "30 billion dollars in VC funding",
563563+}
564564+565565+func CheckRequest(app *model.AppState, next http.Handler) http.Handler {
566566+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
567567+ // requests with empty user agents are considered suspicious.
568568+ // every browser supplies them; hell, even curl supplies them.
569569+ // i only ever see null user-agents paired with malicious requests,
570570+ // so i'm canning them altogether.
571571+ if len(r.Header.Get("User-Agent")) == 0 {
572572+ http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
573573+ return
574574+ }
575575+576576+ // same with .php and awkward double-slash requests.
577577+ // obviously these don't affect me, but these tend to be lazy intrusion
578578+ // attempts. if that's what you're about, i don't want you on my site.
579579+ if strings.HasPrefix(r.URL.Path, "//") ||
580580+ strings.HasSuffix(r.URL.Path, ".php") ||
581581+ strings.HasSuffix(r.URL.Path, ".php7") {
582582+ http.NotFound(w, r)
583583+ fmt.Fprintf(
584584+ os.Stderr,
585585+ "WARN: Suspicious activity blocked: {\"path\":\"%s\",\"address\":\"%s\"}\n",
586586+ r.URL.Path,
587587+ r.RemoteAddr,
588588+ )
589589+ return
590590+ }
591591+592592+ next.ServeHTTP(w, r)
593593+ })
563594}
564595565596func DefaultHeaders(next http.Handler) http.Handler {