From 4d7024e7ddfb9d6abc94bb000ae1f429eefcbea8 Mon Sep 17 00:00:00 2001 From: Hidde-Jan Jongsma Date: Tue, 1 Jul 2025 11:44:15 +0200 Subject: [PATCH] Respond with 404 on unknown routes --- handlers/dashboard.go | 6 +++--- routes/routes.go | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/handlers/dashboard.go b/handlers/dashboard.go index 45dde7a..85e8ebd 100644 --- a/handlers/dashboard.go +++ b/handlers/dashboard.go @@ -10,9 +10,9 @@ import ( "github.com/gin-gonic/gin" ) -func ErrorPage(context *gin.Context) { - render := utils.NewTempl(context, http.StatusOK, layouts.Error404()) - context.Render(http.StatusOK, render) +func NotFoundPage(context *gin.Context) { + render := utils.NewTempl(context, http.StatusNotFound, layouts.Error404()) + context.Render(http.StatusNotFound, render) } func HomeDashboard(context *gin.Context) { diff --git a/routes/routes.go b/routes/routes.go index f9f556f..4615beb 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -18,10 +18,7 @@ import ( const requiredGroupPermission = "soarca_admin" func Setup(app *gin.Engine) { - app.GET("/404-page", handlers.ErrorPage) - app.NoRoute(func(ctx *gin.Context) { - ctx.Redirect(http.StatusTemporaryRedirect, "/404-page") - }) + app.NoRoute(handlers.NotFoundPage) authEnabled, _ := strconv.ParseBool(utils.GetEnv("AUTH_ENABLED", "false")) reporter := soarca.NewReport(utils.GetEnv("SOARCA_URI", "http://localhost:8080"), &http.Client{}, authEnabled) @@ -110,4 +107,4 @@ func ManualRoutes(manual backend.Manual, app *gin.RouterGroup, authentication bo manualRoutes.GET("/", manualHandler.ManualActionsHandler) manualRoutes.POST("/continue", manualHandler.ManualContinueHandler) } -} \ No newline at end of file +}