Skip to content

Commit

Permalink
Skip CSRF for embeds
Browse files Browse the repository at this point in the history
The CSRF middleware sets a _csrf cookie also for loading the embed
javascript on third-party sites. With this change no _csrf cookie is set
when loading the embed javascript (regardless if third-party site or
first-party).
  • Loading branch information
x-way committed Dec 17, 2024
1 parent 4c5a7bd commit be6715c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ func NewServer(isDev bool, sessionsPath string, ignoreCsrf bool) *Server {
CookiePath: "/",
CookieHTTPOnly: true,
CookieSameSite: http.SameSiteStrictMode,
Skipper: func(ctx echo.Context) bool {
/* skip CSRF for embeds */
gistName := ctx.Param("gistname")
if filepath.Ext(gistName) == ".js" {
return true
}
return false
},
}))
g1.Use(csrfInit)
}
Expand Down

0 comments on commit be6715c

Please sign in to comment.