diff --git a/handlers/news.go b/handlers/news.go index 1aff94d..9fbe070 100644 --- a/handlers/news.go +++ b/handlers/news.go @@ -26,6 +26,11 @@ func NewsHandler(app *App) http.HandlerFunc { } if r.Method == http.MethodPost && loggedIn && isAdmin { + if !app.validateCSRFToken(r, session) { + http.Error(w, "Invalid CSRF token", http.StatusForbidden) + return + } + if action := r.URL.Query().Get("action"); action == "delete" { newsIDStr := r.URL.Query().Get("id") newsID, err := strconv.Atoi(newsIDStr) @@ -85,6 +90,7 @@ func NewsHandler(app *App) http.HandlerFunc { BasePath: app.Config.ThreadrDir, StaticPath: app.Config.ThreadrDir + "/static", CurrentURL: r.URL.RequestURI(), + CSRFToken: app.csrfToken(session), }, News: newsItems, IsAdmin: isAdmin, diff --git a/templates/pages/news.html b/templates/pages/news.html index f63ba2c..ad1c8c8 100644 --- a/templates/pages/news.html +++ b/templates/pages/news.html @@ -20,6 +20,7 @@
{{.Content}}
{{if $.IsAdmin}} {{end}} @@ -34,6 +35,7 @@