From a82a603db652274f23f8b3f17f5dabf0c1f49cd5 Mon Sep 17 00:00:00 2001 From: dnaq Date: Fri, 3 Mar 2023 17:14:30 +0100 Subject: [PATCH] Return 404 on unmatched routes (#1201) --- app.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index 47a88707..219f64fa 100644 --- a/app.go +++ b/app.go @@ -521,7 +521,7 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *mux.Router { apiRouter.Use(h.httpAuthenticationMiddleware) apiRouter.PathPrefix("/v1/").HandlerFunc(grpcMux.ServeHTTP) - router.PathPrefix("/").HandlerFunc(stdoutHandler) + router.PathPrefix("/").HandlerFunc(notFoundHandler) return router } @@ -957,7 +957,7 @@ func (h *Headscale) getLastStateChange(users ...User) time.Time { } } -func stdoutHandler( +func notFoundHandler( writer http.ResponseWriter, req *http.Request, ) { @@ -969,6 +969,7 @@ func stdoutHandler( Interface("url", req.URL). Bytes("body", body). Msg("Request did not match") + writer.WriteHeader(http.StatusNotFound) } func readOrCreatePrivateKey(path string) (*key.MachinePrivate, error) {