diff --git a/object/record.go b/object/record.go index 2c54897d..803a5aca 100644 --- a/object/record.go +++ b/object/record.go @@ -52,6 +52,10 @@ type Record struct { func NewRecord(ctx *context.Context) *Record { ip := strings.Replace(util.GetIPFromRequest(ctx.Request), ": ", "", -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{ Name: util.GenerateId(), @@ -59,7 +63,7 @@ func NewRecord(ctx *context.Context) *Record { ClientIp: ip, User: "", Method: ctx.Request.Method, - RequestUri: ctx.Request.RequestURI, + RequestUri: requestUri, Action: action, IsTriggered: false, } diff --git a/util/path.go b/util/path.go index 25556777..550b3daa 100644 --- a/util/path.go +++ b/util/path.go @@ -42,3 +42,31 @@ func GetUrlHost(urlString string) string { u, _ := url.Parse(urlString) 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 + } +} \ No newline at end of file