Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Prevent Imps with duplicate IDs (prebid#703)
Browse files Browse the repository at this point in the history
* Prevent Imps with duplicate IDs.

* Added an initial capacity to the map.
  • Loading branch information
dbemiller authored and hhhjort committed Nov 7, 2018
1 parent f29e583 commit 7a86a21
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,13 @@ func (deps *endpointDeps) validateRequest(req *openrtb.BidRequest) []error {
}
}

impIDs := make(map[string]int, len(req.Imp))
for index := range req.Imp {
imp := &req.Imp[index]
if firstIndex, ok := impIDs[imp.ID]; ok {
errL = append(errL, fmt.Errorf(`request.imp[%d].id and request.imp[%d].id are both "%s". Imp IDs must be unique.`, firstIndex, index, imp.ID))
}
impIDs[imp.ID] = index
errs := deps.validateImp(imp, aliases, index)
if len(errs) > 0 {
errL = append(errL, errs...)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"message": "Invalid request: request.imp[0].id and request.imp[1].id are both \"some-impression-id\". Imp IDs must be unique.\n",
"requestPayload": {
"id": "some-request-id",
"site": {
"page": "prebid.org"
},
"imp": [
{
"id": "some-impression-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"appnexus": {
"placementId": 10433394
}
}
},
{
"id": "some-impression-id",
"banner": {
"format": [
{
"w": 200,
"h": 250
}
]
},
"ext": {
"appnexus": {
"placementId": 10433395
}
}
}
],
"tmax": 500
}
}

0 comments on commit 7a86a21

Please sign in to comment.