Skip to content

Commit

Permalink
Read csrf token from cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
dongxuny committed Apr 9, 2024
1 parent 663e2f1 commit 1f210eb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions middleware/csrf/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,15 @@ func csrfTokenFromQuery(param string) csrfHttpExtractor {
return token, nil
}
}

// csrfTokenFromCookie returns a `csrfTokenExtractor` that extracts token from the
// provided cookie.
func csrfTokenFromCookie(param string) csrfHttpExtractor {
return func(req *http.Request) (string, error) {
cookie, err := req.Cookie(param)
if cookie == nil || err != nil {
return "", errors.New("missing csrf token in the cookie")
}
return cookie.Value, nil
}
}

0 comments on commit 1f210eb

Please sign in to comment.