fix: set samesite mode for CSRF cookie based on security policy (#6914)

This commit is contained in:
Livio Spring 2023-11-14 11:01:59 +02:00 committed by GitHub
parent bd63fcd15d
commit 1344760369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -130,11 +130,16 @@ func createCSRFInterceptor(cookieName string, csrfCookieKey []byte, externalSecu
handler.ServeHTTP(w, r)
return
}
sameSiteMode := csrf.SameSiteLaxMode
if len(authz.GetInstance(r.Context()).SecurityPolicyAllowedOrigins()) > 0 {
sameSiteMode = csrf.SameSiteNoneMode
}
csrf.Protect(csrfCookieKey,
csrf.Secure(externalSecure),
csrf.CookieName(http_utils.SetCookiePrefix(cookieName, "", path, externalSecure)),
csrf.Path(path),
csrf.ErrorHandler(errorHandler),
csrf.SameSite(sameSiteMode),
)(handler).ServeHTTP(w, r)
})
}