diff --git a/routers/base.go b/routers/base.go index 9cbaad3f..997d1d99 100644 --- a/routers/base.go +++ b/routers/base.go @@ -171,6 +171,14 @@ func getHostname(s string) string { return res } +func removePort(s string) string { + ipStr, _, err := net.SplitHostPort(s) + if err != nil { + ipStr = s + } + return ipStr +} + func isHostIntranet(s string) bool { ipStr, _, err := net.SplitHostPort(s) if err != nil { diff --git a/routers/cors_filter.go b/routers/cors_filter.go index 78c57685..a109108a 100644 --- a/routers/cors_filter.go +++ b/routers/cors_filter.go @@ -44,7 +44,7 @@ func CorsFilter(ctx *context.Context) { origin := ctx.Input.Header(headerOrigin) originConf := conf.GetConfigString("origin") originHostname := getHostname(origin) - host := ctx.Request.Host + host := removePort(ctx.Request.Host) if strings.HasPrefix(origin, "http://localhost") || strings.HasPrefix(origin, "https://localhost") || strings.HasPrefix(origin, "http://127.0.0.1") || strings.HasPrefix(origin, "http://casdoor-app") { setCorsHeaders(ctx, origin)