Skip to content

Commit

Permalink
UOE-11332: validate bids as per imp.video.protocols for all the bidde…
Browse files Browse the repository at this point in the history
…rs (#963)
  • Loading branch information
Pubmatic-Supriya-Patil authored Nov 22, 2024
1 parent 5c5c536 commit b12cfb5
Show file tree
Hide file tree
Showing 12 changed files with 1,502 additions and 7 deletions.
1 change: 1 addition & 0 deletions errortypes/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
SecCookieDeprecationLenWarningCode
SecBrowsingTopicsWarningCode
AdpodPostFilteringWarningCode
InvalidVastVersionWarningCode
)

// Coder provides an error or warning code with severity.
Expand Down
5 changes: 5 additions & 0 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ func (e *exchange) HoldAuction(ctx context.Context, r *AuctionRequest, debugLog
recordBids(ctx, e.me, r.PubID, adapterBids)
recordVastVersion(e.me, adapterBids)

if requestExtPrebid.StrictVastMode {
validationErrs := filterBidsByVastVersion(adapterBids, &seatNonBid)
errs = append(errs, validationErrs...)
}

if e.priceFloorEnabled {
var rejectedBids []*entities.PbsOrtbSeatBid
var enforceErrs []error
Expand Down
53 changes: 53 additions & 0 deletions exchange/exchange_ow.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import (
"fmt"
"net/url"
"regexp"
"strconv"
"strings"

"github.com/golang/glog"
"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/currency"
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/exchange/entities"
"github.com/prebid/prebid-server/v2/metrics"
pubmaticstats "github.com/prebid/prebid-server/v2/metrics/pubmatic_stats"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/nbr"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/ortb"
"github.com/prebid/prebid-server/v2/util/jsonutil"
Expand All @@ -36,6 +39,11 @@ const (
VASTTypeInLineEndTag = "</InLine>"
)

var validVastVersions = map[int]bool{
3: true,
4: true,
}

// VASTTagType describes the allowed values for VASTTagType
type VASTTagType string

Expand Down Expand Up @@ -378,3 +386,48 @@ func (e exchange) updateSeatNonBidsPriceThreshold(seatNonBids *openrtb_ext.NonBi
}
}
}

func updateSeatNonBidsInvalidVastVersion(seatNonBids *openrtb_ext.NonBidCollection, seat string, rejectedBids []*entities.PbsOrtbBid) {
for _, pbsRejBid := range rejectedBids {
nonBidParams := entities.GetNonBidParamsFromPbsOrtbBid(pbsRejBid, seat)
nonBidParams.NonBidReason = int(nbr.LossBidLostInVastVersionValidation)
seatNonBids.AddBid(openrtb_ext.NewNonBid(nonBidParams), seat)
}
}

func filterBidsByVastVersion(adapterBids map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid, seatNonBid *openrtb_ext.NonBidCollection) []error {
errs := []error{}
for _, seatBid := range adapterBids {
rejectedBid := []*entities.PbsOrtbBid{}
validBids := make([]*entities.PbsOrtbBid, 0, len(seatBid.Bids))
for _, pbsBid := range seatBid.Bids {
if pbsBid.BidType == openrtb_ext.BidTypeVideo && pbsBid.Bid.AdM != "" {
isValid, vastVersion := validateVastVersion(pbsBid.Bid.AdM)
if !isValid {
errs = append(errs, &errortypes.Warning{
Message: fmt.Sprintf("%s Bid %s was filtered for Imp %s with Vast Version %s: Incompatible with GAM unwinding requirements", seatBid.Seat, pbsBid.Bid.ID, pbsBid.Bid.ImpID, vastVersion),
WarningCode: errortypes.InvalidVastVersionWarningCode,
})
rejectedBid = append(rejectedBid, pbsBid)
continue
}
}
validBids = append(validBids, pbsBid)
}
updateSeatNonBidsInvalidVastVersion(seatNonBid, seatBid.Seat, rejectedBid)
seatBid.Bids = validBids
}
return errs
}

func validateVastVersion(adM string) (bool, string) {
matches := vastVersionRegex.FindStringSubmatch(adM)
if len(matches) != 2 {
return false, ""
}
vastVersionFloat, err := strconv.ParseFloat(matches[1], 64)
if err != nil {
return false, matches[1]
}
return validVastVersions[int(vastVersionFloat)], matches[1]
}
Loading

0 comments on commit b12cfb5

Please sign in to comment.