mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: fix csrf error message on empty session header (#14018)
* chore: fix csrf error message on empty session header A more detailed error message was added to catch mismatched session tokens. This error was mistakenly applying to all CSRF failures.
This commit is contained in:
@ -22,7 +22,9 @@ func CSRF(secureCookie bool) func(next http.Handler) http.Handler {
|
||||
mw.SetBaseCookie(http.Cookie{Path: "/", HttpOnly: true, SameSite: http.SameSiteLaxMode, Secure: secureCookie})
|
||||
mw.SetFailureHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
sessCookie, err := r.Cookie(codersdk.SessionTokenCookie)
|
||||
if err == nil && r.Header.Get(codersdk.SessionTokenHeader) != sessCookie.Value {
|
||||
if err == nil &&
|
||||
r.Header.Get(codersdk.SessionTokenHeader) != "" &&
|
||||
r.Header.Get(codersdk.SessionTokenHeader) != sessCookie.Value {
|
||||
// If a user is using header authentication and cookie auth, but the values
|
||||
// do not match, the cookie value takes priority.
|
||||
// At the very least, return a more helpful error to the user.
|
||||
|
Reference in New Issue
Block a user