From 7a86a21f29db55b23bb4abc8846df97ead0cac2f Mon Sep 17 00:00:00 2001 From: dbemiller <27972385+dbemiller@users.noreply.github.com> Date: Wed, 7 Nov 2018 14:00:29 -0500 Subject: [PATCH] Prevent Imps with duplicate IDs (#703) * Prevent Imps with duplicate IDs. * Added an initial capacity to the map. --- endpoints/openrtb2/auction.go | 5 +++ .../invalid-whole/imp-id-duplicates.json | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 endpoints/openrtb2/sample-requests/invalid-whole/imp-id-duplicates.json diff --git a/endpoints/openrtb2/auction.go b/endpoints/openrtb2/auction.go index a29e108f34a..ef4f6abd176 100644 --- a/endpoints/openrtb2/auction.go +++ b/endpoints/openrtb2/auction.go @@ -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...) diff --git a/endpoints/openrtb2/sample-requests/invalid-whole/imp-id-duplicates.json b/endpoints/openrtb2/sample-requests/invalid-whole/imp-id-duplicates.json new file mode 100644 index 00000000000..095542ef59e --- /dev/null +++ b/endpoints/openrtb2/sample-requests/invalid-whole/imp-id-duplicates.json @@ -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 + } +}