Add CSRF protection for cookie-authenticated requests

This commit is contained in:
root
2026-03-23 16:20:26 +01:00
parent a3348e8795
commit fae7f80913
8 changed files with 139 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"ResendIt/internal/api/middleware"
"ResendIt/internal/auth"
"ResendIt/internal/db"
"ResendIt/internal/file"
@@ -38,6 +39,9 @@ func main() {
r := gin.Default()
// CSRF: set a token cookie for browsers and enforce it on unsafe /api calls.
r.Use(middleware.EnsureCSRFCookie())
r.MaxMultipartMemory = 10 << 30
r.SetFuncMap(template.FuncMap{
"add": func(a, b int) int { return a + b },
@@ -74,6 +78,7 @@ func main() {
createAdminUser(userService)
apiRoute := r.Group("/api")
apiRoute.Use(middleware.CSRFMiddleware())
auth.RegisterRoutes(apiRoute, authHandler)
user.RegisterRoutes(apiRoute, userHandler)