Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/adapters/bidderFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,16 @@ export function isValid(adUnitCode: string, bid: Bid, {index = auctionManager.in
return false;
}

if (bid.mediaType) {
const mediaTypes = index.getMediaTypes(bid);
if (mediaTypes && Object.keys(mediaTypes).length > 0) {
if (!mediaTypes.hasOwnProperty(bid.mediaType)) {
Comment on lines +689 to +692

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Skip media-type guard when response omitted mediaType

This validation runs on prebidBid objects built via createBid(), which pre-populates mediaType as 'banner', so the if (bid.mediaType) guard is effectively always true in the adapter pipeline. As a result, adapters that legitimately omit mediaType in interpretResponse (for example modules/slimcutBidAdapter.js, which supports video but does not set mediaType) will now have video-only ad unit bids rejected here as banner mismatches, even though the new behavior is intended to skip validation when mediaType is unset.

Useful? React with 👍 / 👎.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex can you draft a fix

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex couldn't complete this request. Try again later.

logError(errorMessage(`Bid mediaType '${bid.mediaType}' is not supported by the ad unit. Allowed: ${Object.keys(mediaTypes).join(', ')}`));
return false;
}
}
}

if (FEATURES.NATIVE && bid.mediaType === 'native' && !nativeBidIsValid(bid, {index})) {
logError(errorMessage('Native bid missing some required properties.'));
return false;
Expand Down
66 changes: 66 additions & 0 deletions test/spec/unit/core/bidderFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,72 @@ describe('bidderFactory', () => {
});
});
})

describe('media type validation', () => {
let req;

function mkResponse(props) {
return Object.assign({
requestId: req.bidId,
cpm: 1,
ttl: 60,
creativeId: '123',
netRevenue: true,
currency: 'USD',
width: 1,
height: 2,
}, props);
}

function checkValid(bid) {
return isValid('au', bid, {index: stubAuctionIndex({bidRequests: [req]})});
}

beforeEach(() => {
req = {
...MOCK_BIDS_REQUEST.bids[0],
mediaTypes: {
banner: {
sizes: [[1, 2]]
}
}
};
});

it('should reject video bid when ad unit only has banner', () => {
expect(checkValid(mkResponse({mediaType: 'video'}))).to.be.false;
});

it('should reject banner bid when ad unit only has video', () => {
req.mediaTypes = {video: {context: 'instream'}};
expect(checkValid(mkResponse({mediaType: 'banner'}))).to.be.false;
});

it('should accept banner bid when ad unit has banner', () => {
expect(checkValid(mkResponse({mediaType: 'banner'}))).to.be.true;
});

it('should accept video bid when ad unit has both banner and video', () => {
req.mediaTypes = {
banner: {sizes: [[1, 2]]},
video: {context: 'instream'}
};
expect(checkValid(mkResponse({mediaType: 'video', vastUrl: 'http://vast.xml'}))).to.be.true;
});

it('should skip check when bid.mediaType is not set', () => {
expect(checkValid(mkResponse({mediaType: undefined}))).to.be.true;
});

it('should skip check when mediaTypes is unavailable from index', () => {
delete req.mediaTypes;
expect(checkValid(mkResponse({mediaType: 'banner'}))).to.be.true;
});

it('should reject native bid when ad unit only has banner', () => {
expect(checkValid(mkResponse({mediaType: 'native'}))).to.be.false;
});
});
});

describe('gzip compression', () => {
Expand Down
Loading