You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CORS code has been unmaintained for long time, and the behavior is
not correct.
This PR tries to improve it. The key point is written as comment in
code. And add more tests.
Fixgo-gitea#28515Fixgo-gitea#27642Fixgo-gitea#17098
Copy file name to clipboardexpand all lines: modules/setting/cors.go
+1-3
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,7 @@ import (
12
12
// CORSConfig defines CORS settings
13
13
varCORSConfig=struct {
14
14
Enabledbool
15
-
Schemestring
16
-
AllowDomain []string
17
-
AllowSubdomainbool
15
+
AllowDomain []string// FIXME: this option is from legacy code, it actually works as "AllowedOrigins". When refactoring in the future, the config option should also be renamed together.
// it should explicitly deny OPTIONS requests if CORS handler is not executed, to avoid the next GET/POST handler being incorrectly called by the OPTIONS request
83
+
w.WriteHeader(http.StatusMethodNotAllowed)
84
+
}
85
+
return
86
+
}
87
+
// for non-OPTIONS requests, call the CORS handler to add some related headers like "Vary"
88
+
ifcorsHandler!=nil {
89
+
corsHandler(next).ServeHTTP(w, r)
90
+
} else {
91
+
next.ServeHTTP(w, r)
92
+
}
93
+
})
79
94
}
80
95
}
81
96
@@ -218,7 +233,7 @@ func Routes() *web.Route {
218
233
routes:=web.NewRoute()
219
234
220
235
routes.Head("/", misc.DummyOK) // for health check - doesn't need to be passed through gzip handler
0 commit comments