fix: validate CSRF on non-safe methods
- CSRF has to be validated for any request that can change the state, in practice this means any HTTP request where the method isn't GET/HEAD/OPTIONS. - The code only considered POST to be a state-changing request. - Forgejo has several PUT/DELETE (that changes state) routes for which no CSRF was being validated. - Change the code to validate CSRF for all non-"safe" methods.
This commit is contained in:
parent
9828aca733
commit
4dfb3facb4
1 changed files with 2 additions and 1 deletions
|
@ -192,7 +192,8 @@ func verifyAuthWithOptions(options *common.VerifyOptions) func(ctx *context.Cont
|
|||
return
|
||||
}
|
||||
|
||||
if !options.SignOutRequired && !options.DisableCSRF && ctx.Req.Method == "POST" {
|
||||
safeMethod := ctx.Req.Method == "GET" || ctx.Req.Method == "HEAD" || ctx.Req.Method == "OPTIONS"
|
||||
if !options.SignOutRequired && !options.DisableCSRF && !safeMethod {
|
||||
ctx.Csrf.Validate(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue