From b52c712770dbc9b0b0adb8a106427fa59a9de7f8 Mon Sep 17 00:00:00 2001 From: GrĂ©goire DuchĂȘne Date: Sat, 4 Jun 2022 16:57:57 +0100 Subject: Return 404 when the package name does not match --- resp.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'resp.go') diff --git a/resp.go b/resp.go index b213f58..deae50a 100644 --- a/resp.go +++ b/resp.go @@ -35,6 +35,10 @@ func (h *redirector) ServeHTTP(w http.ResponseWriter, req *http.Request) { } pkg := path.Join(req.Host, req.URL.Path) + if !h.re.MatchString(pkg) { + w.WriteHeader(http.StatusNotFound) + return + } if req.URL.Query().Get("go-get") != "1" { w.Header().Set("Location", "https://pkg.go.dev/"+pkg) w.WriteHeader(http.StatusFound) -- cgit v1.2.3-70-g09d2