From 1ccf093803bcc342e25f269c40b02f83be50b341 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 22 Nov 2017 15:58:03 -0600 Subject: origin checker refactor (#7889) --- utils/api.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'utils') diff --git a/utils/api.go b/utils/api.go index a96e98254..48382d1fe 100644 --- a/utils/api.go +++ b/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) { -- cgit v1.2.3-1-g7c22