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 @@ -2590,6 +2590,10 @@ function updateDeadline(deadlineString) {
2590
2590
data : JSON . stringify ( {
2591
2591
'due_date' : realDeadline ,
2592
2592
} ) ,
2593
+ headers : {
2594
+ 'X-Csrf-Token' : csrf ,
2595
+ 'X-Remote' : true ,
2596
+ } ,
2593
2597
contentType : 'application/json' ,
2594
2598
type : 'POST' ,
2595
2599
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