From a8e541159bd2ae996e329a51d999883cb675ceac Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Tue, 26 Sep 2023 00:03:26 +0800 Subject: [PATCH] Allow localhost in CorsFilter --- routers/cors_filter.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/routers/cors_filter.go b/routers/cors_filter.go index 1bc81826..656cd05f 100644 --- a/routers/cors_filter.go +++ b/routers/cors_filter.go @@ -16,6 +16,7 @@ package routers import ( "net/http" + "strings" "github.com/beego/beego/context" "github.com/casdoor/casdoor/conf" @@ -39,6 +40,11 @@ func CorsFilter(ctx *context.Context) { origin := ctx.Input.Header(headerOrigin) originConf := conf.GetConfigString("origin") + if strings.HasPrefix(origin, "http://localhost") { + setCorsHeaders(ctx, origin) + return + } + if ctx.Request.Method == "POST" && ctx.Request.RequestURI == "/api/login/oauth/access_token" { setCorsHeaders(ctx, origin) return