Skip to content

Commit

Permalink
fix inconsistent cookies, set csrf cookie path
Browse files Browse the repository at this point in the history
while working on the /set-language route, i noticed that i was getting a
csrf error for all /admin views when setting the language, while it
worked well on non-admin routes.

the issue, it turned out, was that we needed to configure gorilla's csrf
feature to set all cookies on the same route. when unconfigured, the
set cookies will only be set for the path they are being set at.

see more in the gorilla.csrf documentation (in particular the csrf.Path
option): https://pkg.go.dev/github.com/gorilla/csrf?utm_source=godoc#Path
  • Loading branch information
cblgh committed Apr 19, 2021
1 parent 2e532c2 commit bbd77b4
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions web/handlers/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func New(
}

CSRF := csrf.Protect(csrfKey,
csrf.Path("/"),
csrf.ErrorHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
err := csrf.FailureReason(req)
// TODO: localize error?
Expand Down

0 comments on commit bbd77b4

Please sign in to comment.