Skip to content

Commit abc4e6d

Browse files
committed
use middleware.DeleteCSRFCookie to replace duplicate code
1 parent 9c5b27b commit abc4e6d

File tree

2 files changed

+1
-17
lines changed

2 files changed

+1
-17
lines changed

modules/context/csrf.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,7 @@ func NewCSRFProtector(opt CsrfOptions, ctx *Context) CSRFProtector {
223223

224224
func (c *csrfProtector) validateToken(ctx *Context, token string) bool {
225225
if !ValidCsrfToken(token, c.Secret, c.ID, "POST", time.Now()) {
226-
// Delete the cookie
227-
middleware.SetCookie(ctx.Resp, c.Cookie, "",
228-
-1,
229-
c.CookiePath,
230-
c.CookieDomain) // FIXME: Do we need to set the Secure, httpOnly and SameSite values too?
231-
226+
middleware.DeleteCSRFCookie(ctx.Resp)
232227
if middleware.IsAPIPath(ctx.Req) {
233228
http.Error(ctx.Resp, "Invalid CSRF token.", http.StatusBadRequest)
234229
} else {

modules/web/middleware/cookie.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,6 @@ func DeleteRedirectToCookie(resp http.ResponseWriter) {
9898
SameSite(setting.SessionConfig.SameSite))
9999
}
100100

101-
// DeleteSesionConfigPathCookie convenience function to delete SessionConfigPath cookies consistently
102-
func DeleteSesionConfigPathCookie(resp http.ResponseWriter, name string) {
103-
SetCookie(resp, name, "",
104-
-1,
105-
setting.SessionConfig.CookiePath,
106-
setting.SessionConfig.Domain,
107-
setting.SessionConfig.Secure,
108-
true,
109-
SameSite(setting.SessionConfig.SameSite))
110-
}
111-
112101
// DeleteCSRFCookie convenience function to delete SessionConfigPath cookies consistently
113102
func DeleteCSRFCookie(resp http.ResponseWriter) {
114103
SetCookie(resp, setting.CSRFCookieName, "",

0 commit comments

Comments
 (0)