File tree 3 files changed +24
-3
lines changed 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 8
8
"fmt"
9
9
"strings"
10
10
11
+ "github.com/go-macaron/csrf"
12
+
11
13
"code.gitea.io/git"
12
14
"code.gitea.io/gitea/models"
13
15
"code.gitea.io/gitea/modules/base"
@@ -97,6 +99,17 @@ func (ctx *APIContext) SetLinkHeader(total, pageSize int) {
97
99
}
98
100
}
99
101
102
+ // RequireCSRF requires a validated a CSRF token
103
+ func (ctx * APIContext ) RequireCSRF () {
104
+ headerToken := ctx .Req .Header .Get (ctx .csrf .GetHeaderName ())
105
+ formValueToken := ctx .Req .FormValue (ctx .csrf .GetFormName ())
106
+ if len (headerToken ) > 0 || len (formValueToken ) > 0 {
107
+ csrf .Validate (ctx .Context .Context , ctx .csrf )
108
+ } else {
109
+ ctx .Context .Error (401 )
110
+ }
111
+ }
112
+
100
113
// APIContexter returns apicontext as macaron middleware
101
114
func APIContexter () macaron.Handler {
102
115
return func (c * Context ) {
Original file line number Diff line number Diff line change @@ -2595,6 +2595,10 @@ function updateDeadline(deadlineString) {
2595
2595
data : JSON . stringify ( {
2596
2596
'due_date' : realDeadline ,
2597
2597
} ) ,
2598
+ headers : {
2599
+ 'X-Csrf-Token' : csrf ,
2600
+ 'X-Remote' : true ,
2601
+ } ,
2598
2602
contentType : 'application/json' ,
2599
2603
type : 'POST' ,
2600
2604
success : function ( ) {
Original file line number Diff line number Diff line change @@ -174,11 +174,15 @@ func repoAssignment() macaron.Handler {
174
174
175
175
// Contexter middleware already checks token for user sign in process.
176
176
func reqToken () macaron.Handler {
177
- return func (ctx * context.Context ) {
178
- if true != ctx .Data ["IsApiToken" ] {
179
- ctx .Error (401 )
177
+ return func (ctx * context.APIContext ) {
178
+ if true == ctx .Data ["IsApiToken" ] {
179
+ return
180
+ }
181
+ if ctx .IsSigned {
182
+ ctx .RequireCSRF ()
180
183
return
181
184
}
185
+ ctx .Context .Error (401 )
182
186
}
183
187
}
184
188
You can’t perform that action at this time.
0 commit comments