origin checker refactor (#7889)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
77a1dc1f2f
Коммит
1ccf093803
16
utils/api.go
16
utils/api.go
@@ -11,14 +11,12 @@ import (
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
type OriginCheckerProc func(*http.Request) bool
|
||||
|
||||
func OriginChecker(r *http.Request) bool {
|
||||
func CheckOrigin(r *http.Request, allowedOrigins string) bool {
|
||||
origin := r.Header.Get("Origin")
|
||||
if *Cfg.ServiceSettings.AllowCorsFrom == "*" {
|
||||
if allowedOrigins == "*" {
|
||||
return true
|
||||
}
|
||||
for _, allowed := range strings.Split(*Cfg.ServiceSettings.AllowCorsFrom, " ") {
|
||||
for _, allowed := range strings.Split(allowedOrigins, " ") {
|
||||
if allowed == origin {
|
||||
return true
|
||||
}
|
||||
@@ -26,12 +24,10 @@ func OriginChecker(r *http.Request) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func GetOriginChecker(r *http.Request) OriginCheckerProc {
|
||||
if len(*Cfg.ServiceSettings.AllowCorsFrom) > 0 {
|
||||
return OriginChecker
|
||||
func OriginChecker(allowedOrigins string) func(*http.Request) bool {
|
||||
return func(r *http.Request) bool {
|
||||
return CheckOrigin(r, allowedOrigins)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RenderWebError(err *model.AppError, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Ссылка в новой задаче
Block a user