diff --git a/package/gamelog/export.go b/package/gamelog/export.go index f54dc46..80f2397 100644 --- a/package/gamelog/export.go +++ b/package/gamelog/export.go @@ -24,6 +24,7 @@ func (sdk *SDK) GetLogItem(uid, event string, property map[string]any, timezone } else { et = gtime.Now() } + safeProperty(property) pstr, err := json.Marshal(property) if err != nil { g.Log().Errorf(ctx, "GetLogItem Fail ! json marshal property err: %v", err) diff --git a/package/gamelog/sdk.go b/package/gamelog/sdk.go index 0a1c701..8a2e31a 100644 --- a/package/gamelog/sdk.go +++ b/package/gamelog/sdk.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "net/http" + "regexp" "strings" "sync" "time" @@ -15,6 +16,7 @@ import ( "github.com/gogf/gf/v2/net/gclient" "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gtime" + "github.com/gogf/gf/v2/util/gconv" ) type sendBody struct { @@ -66,6 +68,16 @@ var ( ) +var safePropertyRE = regexp.MustCompile(`["'\\\/]`) + +func safeProperty(property map[string]any) { + for k, v := range property { + if _, ok := v.(string); ok { + property[k] = safePropertyRE.ReplaceAllString(gconv.String(v), "*") + } + } +} + func getLocationMapValue(key string) *time.Location { // 1. 先尝试读 value, loaded := locationMap.Load(key) @@ -278,6 +290,7 @@ func (sdk *SDK) Log(uid, event string, property map[string]any, timezone string, if len(property) == 0 { property = map[string]any{"ts": gtime.Now().Timestamp()} } + safeProperty(property) var et *gtime.Time if len(customEventTime) > 0 { et = gtime.NewFromTime(customEventTime[0])