mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 20:50:19 +08:00
fix: panic while insert record when request uri too long (#325)
Signed-off-by: Lex Lim <hyperzlink@outlook.com>
This commit is contained in:
@ -52,6 +52,10 @@ type Record struct {
|
|||||||
func NewRecord(ctx *context.Context) *Record {
|
func NewRecord(ctx *context.Context) *Record {
|
||||||
ip := strings.Replace(util.GetIPFromRequest(ctx.Request), ": ", "", -1)
|
ip := strings.Replace(util.GetIPFromRequest(ctx.Request), ": ", "", -1)
|
||||||
action := strings.Replace(ctx.Request.URL.Path, "/api/", "", -1)
|
action := strings.Replace(ctx.Request.URL.Path, "/api/", "", -1)
|
||||||
|
requestUri := util.FilterQuery(ctx.Request.RequestURI, []string{ "accessToken" })
|
||||||
|
if len(requestUri) > 1000 {
|
||||||
|
requestUri = requestUri[0:1000]
|
||||||
|
}
|
||||||
|
|
||||||
record := Record{
|
record := Record{
|
||||||
Name: util.GenerateId(),
|
Name: util.GenerateId(),
|
||||||
@ -59,7 +63,7 @@ func NewRecord(ctx *context.Context) *Record {
|
|||||||
ClientIp: ip,
|
ClientIp: ip,
|
||||||
User: "",
|
User: "",
|
||||||
Method: ctx.Request.Method,
|
Method: ctx.Request.Method,
|
||||||
RequestUri: ctx.Request.RequestURI,
|
RequestUri: requestUri,
|
||||||
Action: action,
|
Action: action,
|
||||||
IsTriggered: false,
|
IsTriggered: false,
|
||||||
}
|
}
|
||||||
|
28
util/path.go
28
util/path.go
@ -42,3 +42,31 @@ func GetUrlHost(urlString string) string {
|
|||||||
u, _ := url.Parse(urlString)
|
u, _ := url.Parse(urlString)
|
||||||
return fmt.Sprintf("%s://%s", u.Scheme, u.Host)
|
return fmt.Sprintf("%s://%s", u.Scheme, u.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FilterQuery(urlString string, blackList []string) string {
|
||||||
|
urlData, err := url.Parse(urlString)
|
||||||
|
if err != nil {
|
||||||
|
return urlString
|
||||||
|
}
|
||||||
|
|
||||||
|
queries := urlData.Query()
|
||||||
|
retQuery := make(url.Values)
|
||||||
|
inBlackList := false
|
||||||
|
for key, value := range queries {
|
||||||
|
inBlackList = false
|
||||||
|
for _, blackListItem := range blackList {
|
||||||
|
if blackListItem == key {
|
||||||
|
inBlackList = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !inBlackList {
|
||||||
|
retQuery[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(retQuery) > 0 {
|
||||||
|
return urlData.Path + "?" + strings.ReplaceAll(retQuery.Encode(), "%2F", "/")
|
||||||
|
} else {
|
||||||
|
return urlData.Path
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user