Skip to content

Commit

Permalink
Merge pull request #78 from TykTechnologies/TT-9116
Browse files Browse the repository at this point in the history
[TT-9116] Safe checking if string is a valid ObjectID
  • Loading branch information
mativm02 authored Jun 15, 2023
2 parents 8451a35 + ce0cf04 commit b102550
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion persistent/internal/driver/mgo/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func handleQueryValue(key string, value interface{}, search bson.M) {
if isStr && key == "_id" {
ObjectIDs := []model.ObjectID{}
for _, str := range strSlice {
ObjectIDs = append(ObjectIDs, model.ObjectIDHex(str))
if bson.IsObjectIdHex(str) {
ObjectIDs = append(ObjectIDs, model.ObjectIDHex(str))
}
}

search[key] = bson.M{"$in": ObjectIDs}
Expand Down
4 changes: 3 additions & 1 deletion persistent/internal/driver/mongo/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func handleQueryValue(key string, value interface{}, search bson.M) {
if isStrSlice && key == "_id" {
ObjectIDs := []model.ObjectID{}
for _, str := range strSlice {
ObjectIDs = append(ObjectIDs, model.ObjectIDHex(str))
if primitive.IsValidObjectID(str) {
ObjectIDs = append(ObjectIDs, model.ObjectIDHex(str))
}
}

search[key] = bson.M{"$in": ObjectIDs}
Expand Down

0 comments on commit b102550

Please sign in to comment.