Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ func main() {
})),
)

// gorilla/csrf v1.7.x defaults the assumed request scheme to "https" for
// Origin/Referer checks. On plaintext HTTP the browser-sent Origin
// (e.g. http://localhost:8082) won't match, so flag requests as plaintext.
if !cfg.SecureCookies {
inner := csrfMiddleware
csrfMiddleware = func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
inner(next).ServeHTTP(w, csrf.PlaintextHTTPRequest(r))
})
}
}

// Admin routes (under /cm)
admin := r.PathPrefix("/cm").Subrouter()
admin.Use(csrfMiddleware)
Expand Down