mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Add isHostIntranet to CORS filter
This commit is contained in:
@ -16,7 +16,9 @@ package routers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/context"
|
||||
@ -154,3 +156,31 @@ func parseBearerToken(ctx *context.Context) string {
|
||||
|
||||
return tokens[1]
|
||||
}
|
||||
|
||||
func getHostname(s string) string {
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
l, err := url.Parse(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res := l.Hostname()
|
||||
return res
|
||||
}
|
||||
|
||||
func isHostIntranet(s string) bool {
|
||||
ipStr, _, err := net.SplitHostPort(s)
|
||||
if err != nil {
|
||||
ipStr = s
|
||||
}
|
||||
|
||||
ip := net.ParseIP(ipStr)
|
||||
if ip == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return ip.IsPrivate()
|
||||
}
|
||||
|
Reference in New Issue
Block a user