diff --git a/internal/frontend/details.go b/internal/frontend/details.go index 5592665b..f9705160 100644 --- a/internal/frontend/details.go +++ b/internal/frontend/details.go @@ -488,7 +488,7 @@ func (s *Server) servePathNotFoundPage(w http.ResponseWriter, r *http.Request, d } modulePaths, err := candidateModulePaths(fullPath) if err != nil { - return pathNotFoundError(ctx, pathType, fullPath, requestedVersion) + return err } results := s.checkPossibleModulePaths(ctx, db, fullPath, requestedVersion, modulePaths, false) for _, fr := range results { diff --git a/internal/frontend/fetch.go b/internal/frontend/fetch.go index 22303593..80b31272 100644 --- a/internal/frontend/fetch.go +++ b/internal/frontend/fetch.go @@ -469,6 +469,12 @@ func candidateModulePaths(fullPath string) (_ []string, err error) { modulePaths = append([]string{path}, modulePaths...) path += "/" } + if len(modulePaths) == 0 { + return nil, &serverError{ + status: http.StatusBadRequest, + err: fmt.Errorf("invalid path: %q", fullPath), + } + } return modulePaths, nil } diff --git a/internal/frontend/server_test.go b/internal/frontend/server_test.go index 2784e6eb..3cbe016e 100644 --- a/internal/frontend/server_test.go +++ b/internal/frontend/server_test.go @@ -881,6 +881,12 @@ func frontendFetchTestCases() []serverTestCase { in("h3.Fetch-message.js-fetchMessage", text("example.com/unknown"))), requiredExperiments: experiment.NewSet(internal.ExperimentFrontendFetch), }, + { + name: "bad request, invalid github module path, frontend experiment", + urlPath: "/github.com/foo", + wantStatusCode: http.StatusBadRequest, + requiredExperiments: experiment.NewSet(internal.ExperimentFrontendFetch), + }, } }