feat: fix 403 error in CorsFilter

This commit is contained in:
Yang Luo 2023-10-10 18:39:25 +08:00
parent 814d3f749b
commit 0096e47351
2 changed files with 9 additions and 1 deletions

View File

@ -171,6 +171,14 @@ func getHostname(s string) string {
return res return res
} }
func removePort(s string) string {
ipStr, _, err := net.SplitHostPort(s)
if err != nil {
ipStr = s
}
return ipStr
}
func isHostIntranet(s string) bool { func isHostIntranet(s string) bool {
ipStr, _, err := net.SplitHostPort(s) ipStr, _, err := net.SplitHostPort(s)
if err != nil { if err != nil {

View File

@ -44,7 +44,7 @@ func CorsFilter(ctx *context.Context) {
origin := ctx.Input.Header(headerOrigin) origin := ctx.Input.Header(headerOrigin)
originConf := conf.GetConfigString("origin") originConf := conf.GetConfigString("origin")
originHostname := getHostname(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") { 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) setCorsHeaders(ctx, origin)