Repository: prebid/prebid-server
Pull request #2331 (2022-08-01 20:00:28)

Ext Fields Exposed to Bidders
Resolves https://github.com/prebid/prebid-server/issues/2321

SyntaxNode: > Looks good. Just a couple of comments. Also I see on the corresponding issue that the following fields are also permitted:
> 
> ```
> ext.prebid.interstitial
> ext.prebid.multibid (only their value)
> ext.prebid.auctiontimestamp
> ```
> 
> I don't see any evidence that we support these at the moment, however, I do see that multibid is currently being worked on.

`ext.prebid.interstitial` is a typo in the docs and should actually be `device.ext.prebid.interstitial` which does not need to be pruned because it's the only field in that ext.

`ext.prebid.multibid` is not yet implemented in PBS-Go.

`ext.prebid.auctiontimestamp` also doesn't exist in PBS-Go. Not sure why, we should look into that - but I think that's best handled separately.


Patch:
diff --git a/adapters/33across/33across.go b/adapters/33across/33across.go
index 72b91059..a0207f4a 100644
--- a/adapters/33across/33across.go
+++ b/adapters/33across/33across.go
@@ -48,7 +48,7 @@ type bidExt struct {
 }
 
 type bidTtxExt struct {
-	MediaType string `json:mediaType,omitempty`
+	MediaType string `json:"mediaType,omitempty"`
 }
 
 // MakeRequests create the object for TTX Reqeust.
diff --git a/adapters/pubmatic/pubmatic.go b/adapters/pubmatic/pubmatic.go
index 61b0105e..802806da 100644
--- a/adapters/pubmatic/pubmatic.go
+++ b/adapters/pubmatic/pubmatic.go
@@ -7,6 +7,7 @@ import (
 	"strconv"
 	"strings"
 
+	"github.com/buger/jsonparser"
 	"github.com/golang/glog"
 	"github.com/mxmCherry/openrtb/v16/openrtb2"
 	"github.com/prebid/prebid-server/adapters"
@@ -235,8 +236,8 @@ func parseImpressionObject(imp *openrtb2.Imp, extractWrapperExtFromImp, extractP
 	var pubID string
 
 	// PubMatic supports banner and video impressions.
-	if imp.Banner == nil && imp.Video == nil {
-		return wrapExt, pubID, fmt.Errorf("Invalid MediaType. PubMatic only supports Banner and Video. Ignoring ImpID=%s", imp.ID)
+	if imp.Banner == nil && imp.Video == nil && imp.Native == nil {
+		return wrapExt, pubID, fmt.Errorf("invalid MediaType. PubMatic only supports Banner, Video and Native. Ignoring ImpID=%s", imp.ID)
 	}
 
 	if imp.Audio != nil {
@@ -394,13 +395,23 @@ func (a *PubmaticAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externa
 			seat := ""
 			var bidExt *pubmaticBidExt
 			bidType := openrtb_ext.BidTypeBanner
-			if err := json.Unmarshal(bid.Ext, &bidExt); err == nil && bidExt != nil {
+			err := json.Unmarshal(bid.Ext, &bidExt)
+			if err != nil {
+				errs = append(errs, err)
+			} else if bidExt != nil {
 				seat = bidExt.Marketplace
 				if bidExt.VideoCreativeInfo != nil && bidExt.VideoCreativeInfo.Duration != nil {
 					impVideo.Duration = *bidExt.VideoCreativeInfo.Duration
 				}
 				bidType = getBidType(bidExt)
 			}
+
+			if bidType == openrtb_ext.BidTypeNative {
+				if value, _, _, err := jsonparser.Get([]byte(bid.AdM), string(openrtb_ext.BidTypeNative)); err == nil {
+					bid.AdM = string(value)
+				}
+			}
+
 			bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
 				Bid:      &bid,
 				BidType:  bidType,
diff --git a/endpoints/openrtb2/auction.go b/endpoints/openrtb2/auction.go
index 57cffb6f..43dc7a10 100644
--- a/endpoints/openrtb2/auction.go
+++ b/endpoints/openrtb2/auction.go
@@ -1526,6 +1526,10 @@ func setAuctionTypeImplicitly(bidReq *openrtb2.BidRequest) {
 func setSiteImplicitly(httpReq *http.Request, bidReq *openrtb2.BidRequest) {
 	if bidReq.Site == nil || bidReq.Site.Page == "" || bidReq.Site.Domain == "" {
 		referrerCandidate := httpReq.Referer()
+		// If http referer is disabled and thus has empty value - use site.page instead
+		if referrerCandidate == "" && bidReq.Site != nil && bidReq.Site.Page != "" {
+			referrerCandidate = bidReq.Site.Page
+		}
 		if parsedUrl, err := url.Parse(referrerCandidate); err == nil {
 			if domain, err := publicsuffix.EffectiveTLDPlusOne(parsedUrl.Host); err == nil {
 				if bidReq.Site == nil {
diff --git a/exchange/utils.go b/exchange/utils.go
index 8a4e0b68..96e5e2a9 100644
--- a/exchange/utils.go
+++ b/exchange/utils.go
@@ -3,14 +3,14 @@ package exchange
 import (
 	"context"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"math/rand"
 
-	"github.com/prebid/prebid-server/stored_responses"
-
 	"github.com/buger/jsonparser"
 	"github.com/mxmCherry/openrtb/v16/openrtb2"
 	"github.com/prebid/go-gdpr/vendorconsent"
+
 	"github.com/prebid/prebid-server/adapters"
 	"github.com/prebid/prebid-server/config"
 	"github.com/prebid/prebid-server/firstpartydata"
@@ -21,6 +21,7 @@ import (
 	"github.com/prebid/prebid-server/privacy/ccpa"
 	"github.com/prebid/prebid-server/privacy/lmt"
 	"github.com/prebid/prebid-server/schain"
+	"github.com/prebid/prebid-server/stored_responses"
 )
 
 var integrationTypeMap = map[metrics.RequestType]config.IntegrationType{
@@ -55,7 +56,7 @@ func cleanOpenRTBRequests(ctx context.Context,
 		return
 	}
 
-	allowedBidderRequests = make([]BidderRequest, 0, 0)
+	allowedBidderRequests = make([]BidderRequest, 0)
 
 	bidderImpWithBidResp := stored_responses.InitStoredBidResponses(req.BidRequest, auctionReq.StoredBidResponses)
 
@@ -217,7 +218,7 @@ func getAuctionBidderRequests(auctionRequest AuctionRequest,
 		return nil, []error{err}
 	}
 
-	bidderParamsInReqExt, err := adapters.ExtractReqExtBidderParamsEmbeddedMap(req.BidRequest)
+	bidderParamsInReqExt, err := adapters.ExtractReqExtBidderParamsMap(req.BidRequest)
 	if err != nil {
 		return nil, []error{err}
 	}
@@ -236,23 +237,10 @@ func getAuctionBidderRequests(auctionRequest AuctionRequest,
 
 		sChainWriter.Write(&reqCopy, bidder)
 
-		if len(bidderParamsInReqExt) != 0 {
-
-			// Update bidder-params(requestExt.Prebid.BidderParams) for the bidder to only contain bidder-params for
-			// this bidder only and remove bidder-params for all other bidders from requestExt.Prebid.BidderParams
-			params, err := getBidderParamsForBidder(bidderParamsInReqExt, bidder)
-			if err != nil {
-				return nil, []error{err}
-			}
-
-			requestExt.Prebid.BidderParams = params
-		}
-
-		reqExt, err := getExtJson(req.BidRequest, requestExt)
+		reqCopy.Ext, err = buildRequestExtForBidder(bidder, req.BidRequest.Ext, requestExt, bidderParamsInReqExt)
 		if err != nil {
 			return nil, []error{err}
 		}
-		reqCopy.Ext = reqExt
 
 		if err := removeUnpermissionedEids(&reqCopy, bidder, requestExt); err != nil {
 			errs = append(errs, fmt.Errorf("unable to enforce request.ext.prebid.data.eidpermissions because %v", err))
@@ -285,26 +273,41 @@ func getAuctionBidderRequests(auctionRequest AuctionRequest,
 	return bidderRequests, errs
 }
 
-func getBidderParamsForBidder(bidderParamsInReqExt map[string]map[string]json.RawMessage, bidder string) (json.RawMessage, error) {
-	var params json.RawMessage
-	if bidderParams, ok := bidderParamsInReqExt[bidder]; ok {
-		var err error
-		params, err = json.Marshal(bidderParams)
-		if err != nil {
-			return nil, err
-		}
+func buildRequestExtForBidder(bidder string, requestExt json.RawMessage, requestExtParsed *openrtb_ext.ExtRequest, bidderParamsInReqExt map[string]json.RawMessage) (json.RawMessage, error) {
+	if len(requestExt) == 0 || requestExtParsed == nil {
+		return json.RawMessage(``), nil
 	}
-	return params, nil
-}
 
-func getExtJson(req *openrtb2.BidRequest, unpackedExt *openrtb_ext.ExtRequest) (json.RawMessage, error) {
-	if len(req.Ext) == 0 || unpackedExt == nil {
-		return json.RawMessage(``), nil
+	// Resolve Bidder Params
+	var bidderParams json.RawMessage
+	if bidderParamsInReqExt != nil {
+		bidderParams = bidderParamsInReqExt[bidder]
+	}
+
+	// Copy Allowed Fields
+	// Per: https://docs.prebid.org/prebid-server/endpoints/openrtb2/pbs-endpoint-auction.html#prebid-server-ortb2-extension-summary
+	prebid := openrtb_ext.ExtRequestPrebid{
+		Integration:         requestExtParsed.Prebid.Integration,
+		Channel:             requestExtParsed.Prebid.Channel,
+		Debug:               requestExtParsed.Prebid.Debug,
+		CurrencyConversions: requestExtParsed.Prebid.CurrencyConversions,
+		BidderParams:        bidderParams,
+	}
+
+	// Marshal New Prebid Object
+	prebidJson, err := json.Marshal(prebid)
+	if err != nil {
+		return nil, err
 	}
 
-	extCopy := *unpackedExt
-	extCopy.Prebid.SChains = nil
-	return json.Marshal(extCopy)
+	// Update Ext With Prebid Json
+	extMap := make(map[string]json.RawMessage)
+	if err := json.Unmarshal(requestExt, &extMap); err != nil {
+		return nil, err
+	}
+	extMap["prebid"] = prebidJson
+
+	return json.Marshal(extMap)
 }
 
 // extractBuyerUIDs parses the values from user.ext.prebid.buyeruids, and then deletes those values from the ext.
@@ -396,17 +399,28 @@ func splitImps(imps []openrtb2.Imp) (map[string][]openrtb2.Imp, error) {
 }
 
 func createSanitizedImpExt(impExt, impExtPrebid map[string]json.RawMessage) (map[string]json.RawMessage, error) {
-	sanitizedImpExt := make(map[string]json.RawMessage, 3)
+	sanitizedImpExt := make(map[string]json.RawMessage, 6)
+	sanitizedImpPrebidExt := make(map[string]json.RawMessage, 2)
+
+	// copy allowed imp[].ext.prebid fields
+	if v, exists := impExtPrebid["is_rewarded_inventory"]; exists {
+		sanitizedImpPrebidExt["is_rewarded_inventory"] = v
+	}
+
+	if v, exists := impExtPrebid["options"]; exists {
+		sanitizedImpPrebidExt["options"] = v
+	}
 
-	delete(impExtPrebid, openrtb_ext.PrebidExtBidderKey)
-	if len(impExtPrebid) > 0 {
-		if impExtPrebidJSON, err := json.Marshal(impExtPrebid); err == nil {
+	// marshal sanitized imp[].ext.prebid
+	if len(sanitizedImpPrebidExt) > 0 {
+		if impExtPrebidJSON, err := json.Marshal(sanitizedImpPrebidExt); err == nil {
 			sanitizedImpExt[openrtb_ext.PrebidExtKey] = impExtPrebidJSON
 		} else {
 			return nil, fmt.Errorf("cannot marshal ext.prebid: %v", err)
 		}
 	}
 
+	// copy reserved imp[].ext fields known to not be bidder names
 	if v, exists := impExt[openrtb_ext.FirstPartyDataExtKey]; exists {
 		sanitizedImpExt[openrtb_ext.FirstPartyDataExtKey] = v
 	}
@@ -647,7 +661,7 @@ func extractBidRequestExt(bidRequest *openrtb2.BidRequest) (*openrtb_ext.ExtRequ
 	requestExt := &openrtb_ext.ExtRequest{}
 
 	if bidRequest == nil {
-		return requestExt, fmt.Errorf("Error bidRequest should not be nil")
+		return requestExt, errors.New("Error bidRequest should not be nil")
 	}
 
 	if len(bidRequest.Ext) > 0 {
diff --git a/experiment/adscert/SignerLogger.go b/experiment/adscert/SignerLogger.go
new file mode 100644
index 00000000..1d99bcc6
--- /dev/null
+++ b/experiment/adscert/SignerLogger.go
@@ -0,0 +1,38 @@
+package adscert
+
+import (
+	"fmt"
+	"github.com/golang/glog"
+)
+
+type SignerLogger struct {
+}
+
+func (sl *SignerLogger) Debugf(format string, args ...interface{}) {
+	//there is no Debug level in glog
+	glog.Infof(format, args...)
+}
+
+func (sl *SignerLogger) Infof(format string, args ...interface{}) {
+	glog.Infof(format, args...)
+}
+
+func (sl *SignerLogger) Info(format string) {
+	glog.Info(format)
+}
+
+func (sl *SignerLogger) Warningf(format string, args ...interface{}) {
+	glog.Warningf(format, args...)
+}
+
+func (sl *SignerLogger) Errorf(format string, args ...interface{}) {
+	glog.Errorf(format, args...)
+}
+
+func (sl *SignerLogger) Fatalf(format string, args ...interface{}) {
+	glog.Fatalf(format, args...)
+}
+
+func (sl *SignerLogger) Panicf(format string, args ...interface{}) {
+	panic(fmt.Sprintf(format, args...))
+}
diff --git a/experiment/adscert/signer.go b/experiment/adscert/signer.go
index 352aa004..08b3f655 100644
--- a/experiment/adscert/signer.go
+++ b/experiment/adscert/signer.go
@@ -3,6 +3,7 @@ package adscert
 import (
 	"fmt"
 	"github.com/IABTechLab/adscert/pkg/adscert/api"
+	"github.com/IABTechLab/adscert/pkg/adscert/logger"
 	"github.com/IABTechLab/adscert/pkg/adscert/signatory"
 	"github.com/prebid/prebid-server/config"
 )
@@ -22,6 +23,7 @@ func (ns *NilSigner) Sign(destinationURL string, body []byte) (string, error) {
 }
 
 func NewAdCertsSigner(experimentAdCertsConfig config.ExperimentAdsCert) (Signer, error) {
+	logger.SetLoggerImpl(&SignerLogger{})
 	if experimentAdCertsConfig.Mode == config.AdCertsSignerModeInprocess {
 		return newInProcessSigner(experimentAdCertsConfig.InProcess)
 	}
diff --git a/openrtb_ext/imp_deepintent.go b/openrtb_ext/imp_deepintent.go
index 34c537d4..b50c8fe0 100644
--- a/openrtb_ext/imp_deepintent.go
+++ b/openrtb_ext/imp_deepintent.go
@@ -1,5 +1,5 @@
 package openrtb_ext
 
 type ExtImpDeepintent struct {
-	TagID string `json:tagId`
+	TagID string `json:"tagId"`
 }
diff --git a/openrtb_ext/request.go b/openrtb_ext/request.go
index 0fcbf4a7..b3807c5d 100644
--- a/openrtb_ext/request.go
+++ b/openrtb_ext/request.go
@@ -38,27 +38,26 @@ type ExtRequestPrebid struct {
 	Aliases              map[string]string         `json:"aliases,omitempty"`
 	AliasGVLIDs          map[string]uint16         `json:"aliasgvlids,omitempty"`
 	BidAdjustmentFactors map[string]float64        `json:"bidadjustmentfactors,omitempty"`
+	BidderConfigs        []BidderConfig            `json:"bidderconfig,omitempty"`
+	BidderParams         json.RawMessage           `json:"bidderparams,omitempty"`
 	Cache                *ExtRequestPrebidCache    `json:"cache,omitempty"`
 	Channel              *ExtRequestPrebidChannel  `json:"channel,omitempty"`
+	CurrencyConversions  *ExtRequestCurrency       `json:"currency,omitempty"`
 	Data                 *ExtRequestPrebidData     `json:"data,omitempty"`
 	Debug                bool                      `json:"debug,omitempty"`
-	Integration          string                    `json:"integration,omitempty"`
 	Events               json.RawMessage           `json:"events,omitempty"`
+	Experiment           *Experiment               `json:"experiment,omitempty"`
+	Integration          string                    `json:"integration,omitempty"`
+	Passthrough          json.RawMessage           `json:"passthrough,omitempty"`
 	SChains              []*ExtRequestPrebidSChain `json:"schains,omitempty"`
 	StoredRequest        *ExtStoredRequest         `json:"storedrequest,omitempty"`
 	SupportDeals         bool                      `json:"supportdeals,omitempty"`
 	Targeting            *ExtRequestTargeting      `json:"targeting,omitempty"`
-	BidderParams         json.RawMessage           `json:"bidderparams,omitempty"`
 
 	// NoSale specifies bidders with whom the publisher has a legal relationship where the
 	// passing of personally identifiable information doesn't constitute a sale per CCPA law.
 	// The array may contain a single sstar ('*') entry to represent all bidders.
 	NoSale []string `json:"nosale,omitempty"`
-
-	CurrencyConversions *ExtRequestCurrency `json:"currency,omitempty"`
-	BidderConfigs       []BidderConfig      `json:"bidderconfig,omitempty"`
-	Passthrough         json.RawMessage     `json:"passthrough,omitempty"`
-	Experiment          *Experiment         `json:"experiment,omitempty"`
 }
 
 // Experiment defines if experimental features are available for the request
diff --git a/schain/schainwriter.go b/schain/schainwriter.go
index 37d7b631..dbbd91ba 100644
--- a/schain/schainwriter.go
+++ b/schain/schainwriter.go
@@ -79,11 +79,5 @@ func (w SChainWriter) Write(req *openrtb2.BidRequest, bidder string) {
 
 // extPrebidSChainExists checks if an schain exists in the ORTB 2.5 req.ext.prebid.schain location
 func extPrebidSChainExists(reqExt *openrtb_ext.ExtRequest) bool {
-	if reqExt == nil {
-		return false
-	}
-	if reqExt.Prebid.SChains == nil {
-		return false
-	}
-	return true
+	return reqExt != nil && reqExt.Prebid.SChains != nil
 }
diff --git a/static/bidder-info/pubmatic.yaml b/static/bidder-info/pubmatic.yaml
index 1688e639..085acfdb 100644
--- a/static/bidder-info/pubmatic.yaml
+++ b/static/bidder-info/pubmatic.yaml
@@ -6,10 +6,12 @@ capabilities:
     mediaTypes:
       - banner
       - video
+      - native
   site:
     mediaTypes:
       - banner
       - video
+      - native
 userSync:
   iframe:
     url: "https://ads.pubmatic.com/AdServer/js/user_sync.html?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&predirect={{.RedirectURL}}"
diff --git a/static/bidder-info/richaudience.yaml b/static/bidder-info/richaudience.yaml
index 3e45dc0b..3ec74ccd 100644
--- a/static/bidder-info/richaudience.yaml
+++ b/static/bidder-info/richaudience.yaml
@@ -15,3 +15,6 @@ userSync:
   iframe:
     url: "https://sync.richaudience.com/74889303289e27f327ad0c6de7be7264/?consentString={{.GDPRConsent}}&r={{.RedirectURL}}"
     userMacro: "[PDID]"
+  redirect:
+      url: "https://sync.richaudience.com/f7872c90c5d3791e2b51f7edce1a0a5d/?p=pbs&consentString={{.GDPRConsent}}&r={{.RedirectURL}}"
+      userMacro: "[PDID]"


Test patch:
diff --git a/adapters/pubmatic/pubmatictest/exemplary/native.json b/adapters/pubmatic/pubmatictest/exemplary/native.json
new file mode 100644
index 00000000..f299c251
--- /dev/null
+++ b/adapters/pubmatic/pubmatictest/exemplary/native.json
@@ -0,0 +1,116 @@
+{
+  "mockBidRequest": {
+      "id": "test-native-request",
+      "imp": [
+          {
+              "id": "test-native-imp",
+              "native": {
+                  "request": "{\"assets\":[{\"id\":1,\"img\":{\"ext\":{\"image1\":\"image2\"},\"h\": 250,\"mimes\":[\"image\/gif\",\"image\/png\"],\"type\":3,\"w\":300},\"required\":1}]}"
+              },
+              "ext": {
+                  "bidder": {
+                      "publisherId": "999",
+                      "wrapper": {
+                          "version": 1,
+                          "profile": 5123
+                      }
+                  }
+              }
+          }
+      ],
+      "ext": {
+        "prebid": {}
+      },
+      "device": {
+          "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
+      },
+      "site": {
+          "id": "siteID",
+          "publisher": {
+              "id": "1234"
+          }
+      }
+  },
+  "httpCalls": [
+      {
+          "expectedRequest": {
+              "uri": "https://hbopenbid.pubmatic.com/translator?source=prebid-server",
+              "body": {
+                  "id": "test-native-request",
+                  "imp": [
+                      {
+                          "id": "test-native-imp",
+                          "native": {
+                              "request": "{\"assets\":[{\"id\":1,\"img\":{\"ext\":{\"image1\":\"image2\"},\"h\": 250,\"mimes\":[\"image\/gif\",\"image\/png\"],\"type\":3,\"w\":300},\"required\":1}]}"
+                          }
+                      }
+                  ],
+                  "device": {
+                      "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
+                  },
+                  "site": {
+                      "id": "siteID",
+                      "publisher": {
+                          "id": "999"
+                      }
+                  },
+                  "ext": {
+                      "wrapper": {
+                          "profile": 5123,
+                          "version": 1
+                      }
+                  }
+              }
+          },
+          "mockResponse": {
+              "status": 200,
+              "body": {
+                  "id": "test-native-request",
+                  "seatbid": [
+                      {
+                          "seat": "958",
+                          "bid": [
+                              {
+                                  "id": "test-native-request",
+                                  "impid": "test-native-imp",
+                                  "price": 0.500000,
+                                  "adid": "some-test-id",
+                                  "adm": "{\"native\":{\"assets\":[{\"id\":2,\"img\":{\"h\":90,\"url\":\"//ads.pubmatic.com/AdTag/native/728x90.png\",\"w\":728}},{\"data\":{\"value\":\"Sponsored By PubMatic\"},\"id\":4},{\"id\":3,\"img\":{\"h\":90,\"url\":\"//ads.pubmatic.com/AdTag/native/728x90.png\",\"w\":728}},{\"id\":1,\"title\":{\"text\":\"Native Test Title\"}},{\"data\":{\"value\":\"Sponsored By PubMatic\"},\"id\":5}],\"imptrackers\":[\"http://clicktracker.com/AdTag/9bde02d0-6017-11e4-9df7-005056967c35\"],\"jstracker\":\"<script src='\\\/\\\/ads.pubmatic.com\\\/AdTag\\\/native\\\/tempReseponse.js'><script src='\\\/\\\/ads.pubmatic.com\\\/AdTag\\\/native\\\/tempReseponse.js'>\",\"link\":{\"clicktrackers\":[\"http://clicktracker.com/AdTag/9bde02d0-6017-11e4-9df7-005056967c35\"],\"fallback\":\"http://www.pubmatic.com\",\"url\":\"//www.pubmatic.com\"}}}",
+                                  "crid": "29681110",
+                                  "ext": {
+                                      "deal_channel": 1,
+                                      "bidtype": 2
+                                  }
+                              }
+                          ]
+                      }
+                  ],
+                  "bidid": "5778926625248726496",
+                  "cur": "USD"
+              }
+          }
+      }
+  ],
+  "expectedBidResponses": [
+      {
+          "currency": "USD",
+          "bids": [
+              {
+                  "bid": {
+                      "id": "test-native-request",
+                      "impid": "test-native-imp",
+                      "price": 0.5,
+                      "adid": "some-test-id",
+                      "adm": "{\"assets\":[{\"id\":2,\"img\":{\"h\":90,\"url\":\"//ads.pubmatic.com/AdTag/native/728x90.png\",\"w\":728}},{\"data\":{\"value\":\"Sponsored By PubMatic\"},\"id\":4},{\"id\":3,\"img\":{\"h\":90,\"url\":\"//ads.pubmatic.com/AdTag/native/728x90.png\",\"w\":728}},{\"id\":1,\"title\":{\"text\":\"Native Test Title\"}},{\"data\":{\"value\":\"Sponsored By PubMatic\"},\"id\":5}],\"imptrackers\":[\"http://clicktracker.com/AdTag/9bde02d0-6017-11e4-9df7-005056967c35\"],\"jstracker\":\"<script src='\\\/\\\/ads.pubmatic.com\\\/AdTag\\\/native\\\/tempReseponse.js'><script src='\\\/\\\/ads.pubmatic.com\\\/AdTag\\\/native\\\/tempReseponse.js'>\",\"link\":{\"clicktrackers\":[\"http://clicktracker.com/AdTag/9bde02d0-6017-11e4-9df7-005056967c35\"],\"fallback\":\"http://www.pubmatic.com\",\"url\":\"//www.pubmatic.com\"}}",
+                      "crid": "29681110",
+                      "ext": {
+                          "deal_channel": 1,
+                          "bidtype": 2
+                      }
+                  },
+                  "type": "native"
+              }
+          ]
+      }
+  ]
+}
\ No newline at end of file
diff --git a/adapters/pubmatic/pubmatictest/supplemental/app.json b/adapters/pubmatic/pubmatictest/supplemental/app.json
index c6ed97a5..01ba1f2e 100644
--- a/adapters/pubmatic/pubmatictest/supplemental/app.json
+++ b/adapters/pubmatic/pubmatictest/supplemental/app.json
@@ -134,5 +134,11 @@
           }
         ]
       }
+    ],
+    "expectedMakeBidsErrors": [
+      {
+        "value": "unexpected end of JSON input",
+        "comparison": "literal"
+      }
     ]
   }
\ No newline at end of file
diff --git a/adapters/pubmatic/pubmatictest/supplemental/audio.json b/adapters/pubmatic/pubmatictest/supplemental/audio.json
index 2befa39d..4142e334 100644
--- a/adapters/pubmatic/pubmatictest/supplemental/audio.json
+++ b/adapters/pubmatic/pubmatictest/supplemental/audio.json
@@ -22,7 +22,7 @@
 
   "expectedMakeRequestsErrors": [
     {
-      "value": "Invalid MediaType. PubMatic only supports Banner and Video. Ignoring ImpID=unsupported-audio-imp",
+      "value": "invalid MediaType. PubMatic only supports Banner, Video and Native. Ignoring ImpID=unsupported-audio-imp",
       "comparison": "literal"
     }
   ]
diff --git a/endpoints/openrtb2/auction_test.go b/endpoints/openrtb2/auction_test.go
index d9c0710c..54d326c4 100644
--- a/endpoints/openrtb2/auction_test.go
+++ b/endpoints/openrtb2/auction_test.go
@@ -878,22 +878,65 @@ func TestImplicitSecure(t *testing.T) {
 	}
 }
 
-func TestRefererParsing(t *testing.T) {
-	httpReq := httptest.NewRequest("POST", "/openrtb2/auction", strings.NewReader(validRequest(t, "site.json")))
-	httpReq.Header.Set("Referer", "http://test.mysite.com")
-	bidReq := &openrtb2.BidRequest{}
+func TestReferer(t *testing.T) {
+	testCases := []struct {
+		description     string
+		givenSitePage   string
+		givenSiteDomain string
+		givenReferer    string
+		expectedDomain  string
+		expectedPage    string
+	}{
+		{
+			description:    "site.page/domain are unchanged when site.page/domain and http referer are not set",
+			expectedDomain: "",
+			expectedPage:   "",
+		},
+		{
+			description:    "site.page/domain are derived from referer when neither is set and http referer is set",
+			givenReferer:   "https://test.somepage.com",
+			expectedDomain: "somepage.com",
+			expectedPage:   "https://test.somepage.com",
+		},
+		{
+			description:    "site.domain is derived from site.page when site.page is set and http referer is not set",
+			givenSitePage:  "https://test.somepage.com",
+			expectedDomain: "somepage.com",
+			expectedPage:   "https://test.somepage.com",
+		},
+		{
+			description:    "site.domain is derived from http referer when site.page and http referer are set",
+			givenSitePage:  "https://test.somepage.com",
+			givenReferer:   "http://test.com",
+			expectedDomain: "test.com",
+			expectedPage:   "https://test.somepage.com",
+		},
+		{
+			description:     "site.page/domain are unchanged when site.page/domain and http referer are set",
+			givenSitePage:   "https://test.somepage.com",
+			givenSiteDomain: "some.domain.com",
+			givenReferer:    "http://test.com",
+			expectedDomain:  "some.domain.com",
+			expectedPage:    "https://test.somepage.com",
+		},
+	}
 
-	setSiteImplicitly(httpReq, bidReq)
+	for _, test := range testCases {
+		httpReq := httptest.NewRequest("POST", "/openrtb2/auction", strings.NewReader(validRequest(t, "site.json")))
+		httpReq.Header.Set("Referer", test.givenReferer)
 
-	if bidReq.Site == nil {
-		t.Fatalf("bidrequest.site should not be nil.")
-	}
+		bidReq := &openrtb2.BidRequest{
+			Site: &openrtb2.Site{
+				Domain: test.givenSiteDomain,
+				Page:   test.givenSitePage,
+			},
+		}
 
-	if bidReq.Site.Domain != "mysite.com" {
-		t.Errorf("Bad bidrequest.site.domain. Expected mysite.com, got %s", bidReq.Site.Domain)
-	}
-	if bidReq.Site.Page != "http://test.mysite.com" {
-		t.Errorf("Bad bidrequest.site.page. Expected mysite.com, got %s", bidReq.Site.Page)
+		setSiteImplicitly(httpReq, bidReq)
+
+		assert.NotNil(t, bidReq.Site, test.description)
+		assert.Equal(t, test.expectedDomain, bidReq.Site.Domain, test.description)
+		assert.Equal(t, test.expectedPage, bidReq.Site.Page, test.description)
 	}
 }
 
diff --git a/exchange/exchangetest/aliases.json b/exchange/exchangetest/aliases.json
index 59f270e1..8c0bf309 100644
--- a/exchange/exchangetest/aliases.json
+++ b/exchange/exchangetest/aliases.json
@@ -58,11 +58,7 @@
             }
           ],
           "ext": {
-            "prebid": {
-              "aliases": {
-                "districtm": "appnexus"
-              }
-            }
+            "prebid": {}
           }
         }
       },
@@ -94,11 +90,7 @@
             }
           ],
           "ext": {
-            "prebid": {
-              "aliases": {
-                "districtm": "appnexus"
-              }
-            }
+            "prebid": {}
           }
         }
       },
diff --git a/exchange/exchangetest/bidadjustmentfactors.json b/exchange/exchangetest/bidadjustmentfactors.json
index 1f096bfb..8ef413ee 100644
--- a/exchange/exchangetest/bidadjustmentfactors.json
+++ b/exchange/exchangetest/bidadjustmentfactors.json
@@ -56,15 +56,7 @@
             }
           ],
           "ext": {
-            "prebid": {
-              "aliases": {
-                "districtm": "appnexus"
-              },
-              "bidadjustmentfactors": {
-                "appnexus": 2.5,
-                "districtm": 0.3
-              }
-            }
+            "prebid": {}
           }
         },
         "bidAdjustments": {
@@ -97,15 +89,7 @@
             }
           ],
           "ext": {
-            "prebid": {
-              "aliases": {
-                "districtm": "appnexus"
-              },
-              "bidadjustmentfactors": {
-                "appnexus": 2.5,
-                "districtm": 0.3
-              }
-            }
+            "prebid": {}
           }
         },
         "bidAdjustments": {
@@ -129,4 +113,4 @@
       }
     }
   }
-}
+}
\ No newline at end of file
diff --git a/exchange/exchangetest/ccpa-nosale-any-bidder.json b/exchange/exchangetest/ccpa-nosale-any-bidder.json
index db98878d..1774ba7a 100644
--- a/exchange/exchangetest/ccpa-nosale-any-bidder.json
+++ b/exchange/exchangetest/ccpa-nosale-any-bidder.json
@@ -6,17 +6,19 @@
             "site": {
                 "page": "test.somepage.com"
             },
-            "imp": [{
-                "id": "my-imp-id",
-                "video": {
-                    "mimes": ["video/mp4"]
-                },
-                "ext": {
-                    "appnexus": {
-                        "placementId": 1
+            "imp": [
+                {
+                    "id": "my-imp-id",
+                    "video": {
+                        "mimes": ["video/mp4"]
+                    },
+                    "ext": {
+                        "appnexus": {
+                            "placementId": 1
+                        }
                     }
                 }
-            }],
+            ],
             "regs": {
                 "ext": {
                     "us_privacy": "1-Y-"
@@ -40,26 +42,26 @@
                     "site": {
                         "page": "test.somepage.com"
                     },
-                    "imp": [{
-                        "id": "my-imp-id",
-                        "video": {
-                            "mimes": ["video/mp4"]
-                        },
-                        "ext": {
-                            "bidder": {
-                                "placementId": 1
+                    "imp": [
+                        {
+                            "id": "my-imp-id",
+                            "video": {
+                                "mimes": ["video/mp4"]
+                            },
+                            "ext": {
+                                "bidder": {
+                                    "placementId": 1
+                                }
                             }
                         }
-                    }],
+                    ],
                     "regs": {
                         "ext": {
                             "us_privacy": "1-Y-"
                         }
                     },
                     "ext": {
-                        "prebid": {
-                            "nosale": ["*"]
-                        }
+                        "prebid": {}
                     },
                     "user": {
                         "buyeruid": "some-buyer-id"
diff --git a/exchange/exchangetest/ccpa-nosale-specific-bidder.json b/exchange/exchangetest/ccpa-nosale-specific-bidder.json
index ffa4e9c7..219aac48 100644
--- a/exchange/exchangetest/ccpa-nosale-specific-bidder.json
+++ b/exchange/exchangetest/ccpa-nosale-specific-bidder.json
@@ -6,17 +6,19 @@
             "site": {
                 "page": "test.somepage.com"
             },
-            "imp": [{
-                "id": "my-imp-id",
-                "video": {
-                    "mimes": ["video/mp4"]
-                },
-                "ext": {
-                    "appnexus": {
-                        "placementId": 1
+            "imp": [
+                {
+                    "id": "my-imp-id",
+                    "video": {
+                        "mimes": ["video/mp4"]
+                    },
+                    "ext": {
+                        "appnexus": {
+                            "placementId": 1
+                        }
                     }
                 }
-            }],
+            ],
             "regs": {
                 "ext": {
                     "us_privacy": "1-Y-"
@@ -40,26 +42,26 @@
                     "site": {
                         "page": "test.somepage.com"
                     },
-                    "imp": [{
-                        "id": "my-imp-id",
-                        "video": {
-                            "mimes": ["video/mp4"]
-                        },
-                        "ext": {
-                            "bidder": {
-                                "placementId": 1
+                    "imp": [
+                        {
+                            "id": "my-imp-id",
+                            "video": {
+                                "mimes": ["video/mp4"]
+                            },
+                            "ext": {
+                                "bidder": {
+                                    "placementId": 1
+                                }
                             }
                         }
-                    }],
+                    ],
                     "regs": {
                         "ext": {
                             "us_privacy": "1-Y-"
                         }
                     },
                     "ext": {
-                        "prebid": {
-                            "nosale": ["appnexus"]
-                        }
+                        "prebid": {}
                     },
                     "user": {
                         "buyeruid": "some-buyer-id"
diff --git a/exchange/exchangetest/eidpermissions-allowed-alias.json b/exchange/exchangetest/eidpermissions-allowed-alias.json
index 305c1823..fc12c271 100644
--- a/exchange/exchangetest/eidpermissions-allowed-alias.json
+++ b/exchange/exchangetest/eidpermissions-allowed-alias.json
@@ -7,10 +7,12 @@
             },
             "user": {
                 "ext": {
-                    "eids": [{
-                        "source": "source1",
-                        "id": "anyId"
-                    }]
+                    "eids": [
+                        {
+                            "source": "source1",
+                            "id": "anyId"
+                        }
+                    ]
                 }
             },
             "ext": {
@@ -19,24 +21,28 @@
                         "foo": "appnexus"
                     },
                     "data": {
-                        "eidpermissions": [{
-                            "source": "source1",
-                            "bidders": ["foo"]
-                        }]
+                        "eidpermissions": [
+                            {
+                                "source": "source1",
+                                "bidders": ["foo"]
+                            }
+                        ]
                     }
                 }
             },
-            "imp": [{
-                "id": "my-imp-id",
-                "video": {
-                    "mimes": ["video/mp4"]
-                },
-                "ext": {
-                    "foo": {
-                        "placementId": 1
+            "imp": [
+                {
+                    "id": "my-imp-id",
+                    "video": {
+                        "mimes": ["video/mp4"]
+                    },
+                    "ext": {
+                        "foo": {
+                            "placementId": 1
+                        }
                     }
                 }
-            }]
+            ]
         }
     },
     "outgoingRequests": {
@@ -49,76 +55,78 @@
                     },
                     "user": {
                         "ext": {
-                            "eids": [{
-                                "source": "source1",
-                                "id": "anyId"
-                            }]
+                            "eids": [
+                                {
+                                    "source": "source1",
+                                    "id": "anyId"
+                                }
+                            ]
                         }
                     },
                     "ext": {
-                        "prebid": {
-                            "aliases": {
-                                "foo": "appnexus"
-                            },
-                            "data": {
-                                "eidpermissions": [{
-                                    "source": "source1",
-                                    "bidders": ["foo"]
-                                }]
-                            }
-                        }
+                        "prebid": {}
                     },
-                    "imp": [{
-                        "id": "my-imp-id",
-                        "video": {
-                            "mimes": ["video/mp4"]
-                        },
-                        "ext": {
-                            "bidder": {
-                                "placementId": 1
+                    "imp": [
+                        {
+                            "id": "my-imp-id",
+                            "video": {
+                                "mimes": ["video/mp4"]
+                            },
+                            "ext": {
+                                "bidder": {
+                                    "placementId": 1
+                                }
                             }
                         }
-                    }]
+                    ]
                 }
             },
             "mockResponse": {
-                "pbsSeatBids": [{
-                    "pbsBids": [{
-                        "ortbBid": {
-                            "id": "apn-bid",
-                            "impid": "my-imp-id",
-                            "price": 0.3,
-                            "w": 200,
-                            "h": 250,
-                            "crid": "creative-1"
-                        },
-                        "bidType": "video"
-                    }],
-                    "seat": "foo"
-                }]
+                "pbsSeatBids": [
+                    {
+                        "pbsBids": [
+                            {
+                                "ortbBid": {
+                                    "id": "apn-bid",
+                                    "impid": "my-imp-id",
+                                    "price": 0.3,
+                                    "w": 200,
+                                    "h": 250,
+                                    "crid": "creative-1"
+                                },
+                                "bidType": "video"
+                            }
+                        ],
+                        "seat": "foo"
+                    }
+                ]
             }
         }
     },
     "response": {
         "bids": {
             "id": "some-request-id",
-            "seatbid": [{
-                "seat": "foo",
-                "bid": [{
-                    "id": "apn-bid",
-                    "impid": "my-imp-id",
-                    "price": 0.3,
-                    "w": 200,
-                    "h": 250,
-                    "crid": "creative-1",
-                    "ext": {
-                        "origbidcpm": 0.3,
-                        "prebid": {
-                            "type": "video"
+            "seatbid": [
+                {
+                    "seat": "foo",
+                    "bid": [
+                        {
+                            "id": "apn-bid",
+                            "impid": "my-imp-id",
+                            "price": 0.3,
+                            "w": 200,
+                            "h": 250,
+                            "crid": "creative-1",
+                            "ext": {
+                                "origbidcpm": 0.3,
+                                "prebid": {
+                                    "type": "video"
+                                }
+                            }
                         }
-                    }
-                }]
-            }]
+                    ]
+                }
+            ]
         }
     }
 }
\ No newline at end of file
diff --git a/exchange/exchangetest/eidpermissions-allowed.json b/exchange/exchangetest/eidpermissions-allowed.json
index 4687ec5c..953f38f9 100644
--- a/exchange/exchangetest/eidpermissions-allowed.json
+++ b/exchange/exchangetest/eidpermissions-allowed.json
@@ -7,33 +7,39 @@
             },
             "user": {
                 "ext": {
-                    "eids": [{
-                        "source": "source1",
-                        "id": "anyId"
-                    }]
+                    "eids": [
+                        {
+                            "source": "source1",
+                            "id": "anyId"
+                        }
+                    ]
                 }
             },
             "ext": {
                 "prebid": {
                     "data": {
-                        "eidpermissions": [{
-                            "source": "source1",
-                            "bidders": ["appnexus"]
-                        }]
+                        "eidpermissions": [
+                            {
+                                "source": "source1",
+                                "bidders": ["appnexus"]
+                            }
+                        ]
                     }
                 }
             },
-            "imp": [{
-                "id": "my-imp-id",
-                "video": {
-                    "mimes": ["video/mp4"]
-                },
-                "ext": {
-                    "appnexus": {
-                        "placementId": 1
+            "imp": [
+                {
+                    "id": "my-imp-id",
+                    "video": {
+                        "mimes": ["video/mp4"]
+                    },
+                    "ext": {
+                        "appnexus": {
+                            "placementId": 1
+                        }
                     }
                 }
-            }]
+            ]
         }
     },
     "outgoingRequests": {
@@ -46,73 +52,78 @@
                     },
                     "user": {
                         "ext": {
-                            "eids": [{
-                                "source": "source1",
-                                "id": "anyId"
-                            }]
+                            "eids": [
+                                {
+                                    "source": "source1",
+                                    "id": "anyId"
+                                }
+                            ]
                         }
                     },
                     "ext": {
-                        "prebid": {
-                            "data": {
-                                "eidpermissions": [{
-                                    "source": "source1",
-                                    "bidders": ["appnexus"]
-                                }]
-                            }
-                        }
+                        "prebid": {}
                     },
-                    "imp": [{
-                        "id": "my-imp-id",
-                        "video": {
-                            "mimes": ["video/mp4"]
-                        },
-                        "ext": {
-                            "bidder": {
-                                "placementId": 1
+                    "imp": [
+                        {
+                            "id": "my-imp-id",
+                            "video": {
+                                "mimes": ["video/mp4"]
+                            },
+                            "ext": {
+                                "bidder": {
+                                    "placementId": 1
+                                }
                             }
                         }
-                    }]
+                    ]
                 }
             },
             "mockResponse": {
-                "pbsSeatBids": [{
-                    "pbsBids": [{
-                        "ortbBid": {
-                            "id": "apn-bid",
-                            "impid": "my-imp-id",
-                            "price": 0.3,
-                            "w": 200,
-                            "h": 250,
-                            "crid": "creative-1"
-                        },
-                        "bidType": "video"
-                    }],
-                    "seat": "appnexus"
-                }]
+                "pbsSeatBids": [
+                    {
+                        "pbsBids": [
+                            {
+                                "ortbBid": {
+                                    "id": "apn-bid",
+                                    "impid": "my-imp-id",
+                                    "price": 0.3,
+                                    "w": 200,
+                                    "h": 250,
+                                    "crid": "creative-1"
+                                },
+                                "bidType": "video"
+                            }
+                        ],
+                        "seat": "appnexus"
+                    }
+                ]
             }
         }
     },
     "response": {
         "bids": {
             "id": "some-request-id",
-            "seatbid": [{
-                "seat": "appnexus",
-                "bid": [{
-                    "id": "apn-bid",
-                    "impid": "my-imp-id",
-                    "price": 0.3,
-                    "w": 200,
-                    "h": 250,
-                    "crid": "creative-1",
-                    "ext": {
-                        "origbidcpm": 0.3,
-                        "prebid": {
-                            "type": "video"
+            "seatbid": [
+                {
+                    "seat": "appnexus",
+                    "bid": [
+                        {
+                            "id": "apn-bid",
+                            "impid": "my-imp-id",
+                            "price": 0.3,
+                            "w": 200,
+                            "h": 250,
+                            "crid": "creative-1",
+                            "ext": {
+                                "origbidcpm": 0.3,
+                                "prebid": {
+                                    "type": "video"
+                                }
+                            }
                         }
-                    }
-                }]
-            }]
+                    ]
+                }
+            ]
         }
     }
 }
\ No newline at end of file
diff --git a/exchange/exchangetest/eidpermissions-denied.json b/exchange/exchangetest/eidpermissions-denied.json
index 373616f9..1fb91294 100644
--- a/exchange/exchangetest/eidpermissions-denied.json
+++ b/exchange/exchangetest/eidpermissions-denied.json
@@ -7,33 +7,39 @@
             },
             "user": {
                 "ext": {
-                    "eids": [{
-                        "source": "source1",
-                        "id": "anyId"
-                    }]
+                    "eids": [
+                        {
+                            "source": "source1",
+                            "id": "anyId"
+                        }
+                    ]
                 }
             },
             "ext": {
                 "prebid": {
                     "data": {
-                        "eidpermissions": [{
-                            "source": "source1",
-                            "bidders": ["otherBidder"]
-                        }]
+                        "eidpermissions": [
+                            {
+                                "source": "source1",
+                                "bidders": ["otherBidder"]
+                            }
+                        ]
                     }
                 }
             },
-            "imp": [{
-                "id": "my-imp-id",
-                "video": {
-                    "mimes": ["video/mp4"]
-                },
-                "ext": {
-                    "appnexus": {
-                        "placementId": 1
+            "imp": [
+                {
+                    "id": "my-imp-id",
+                    "video": {
+                        "mimes": ["video/mp4"]
+                    },
+                    "ext": {
+                        "appnexus": {
+                            "placementId": 1
+                        }
                     }
                 }
-            }]
+            ]
         }
     },
     "outgoingRequests": {
@@ -44,69 +50,71 @@
                     "site": {
                         "page": "test.somepage.com"
                     },
-                    "user": {
-                    },
+                    "user": {},
                     "ext": {
-                        "prebid": {
-                            "data": {
-                                "eidpermissions": [{
-                                    "source": "source1",
-                                    "bidders": ["otherBidder"]
-                                }]
-                            }
-                        }
+                        "prebid": {}
                     },
-                    "imp": [{
-                        "id": "my-imp-id",
-                        "video": {
-                            "mimes": ["video/mp4"]
-                        },
-                        "ext": {
-                            "bidder": {
-                                "placementId": 1
+                    "imp": [
+                        {
+                            "id": "my-imp-id",
+                            "video": {
+                                "mimes": ["video/mp4"]
+                            },
+                            "ext": {
+                                "bidder": {
+                                    "placementId": 1
+                                }
                             }
                         }
-                    }]
+                    ]
                 }
             },
             "mockResponse": {
-                "pbsSeatBids": [{
-                    "pbsBids": [{
-                        "ortbBid": {
-                            "id": "apn-bid",
-                            "impid": "my-imp-id",
-                            "price": 0.3,
-                            "w": 200,
-                            "h": 250,
-                            "crid": "creative-1"
-                        },
-                        "bidType": "video"
-                    }],
-                    "seat": "appnexus"
-                }]
+                "pbsSeatBids": [
+                    {
+                        "pbsBids": [
+                            {
+                                "ortbBid": {
+                                    "id": "apn-bid",
+                                    "impid": "my-imp-id",
+                                    "price": 0.3,
+                                    "w": 200,
+                                    "h": 250,
+                                    "crid": "creative-1"
+                                },
+                                "bidType": "video"
+                            }
+                        ],
+                        "seat": "appnexus"
+                    }
+                ]
             }
         }
     },
     "response": {
         "bids": {
             "id": "some-request-id",
-            "seatbid": [{
-                "seat": "appnexus",
-                "bid": [{
-                    "id": "apn-bid",
-                    "impid": "my-imp-id",
-                    "price": 0.3,
-                    "w": 200,
-                    "h": 250,
-                    "crid": "creative-1",
-                    "ext": {
-                        "origbidcpm": 0.3,
-                        "prebid": {
-                            "type": "video"
+            "seatbid": [
+                {
+                    "seat": "appnexus",
+                    "bid": [
+                        {
+                            "id": "apn-bid",
+                            "impid": "my-imp-id",
+                            "price": 0.3,
+                            "w": 200,
+                            "h": 250,
+                            "crid": "creative-1",
+                            "ext": {
+                                "origbidcpm": 0.3,
+                                "prebid": {
+                                    "type": "video"
+                                }
+                            }
                         }
-                    }
-                }]
-            }]
+                    ]
+                }
+            ]
         }
     }
 }
\ No newline at end of file
diff --git a/exchange/exchangetest/firstpartydata-multibidder-config-valid.json b/exchange/exchangetest/firstpartydata-multibidder-config-valid.json
index 8ac7e7d2..8788d553 100644
--- a/exchange/exchangetest/firstpartydata-multibidder-config-valid.json
+++ b/exchange/exchangetest/firstpartydata-multibidder-config-valid.json
@@ -105,11 +105,7 @@
             "page": "fpd_appnexus_site_page"
           },
           "ext": {
-            "prebid": {
-              "data": {
-                "eidpermissions": null
-              }
-            }
+            "prebid": {}
           }
         }
       }
@@ -147,15 +143,10 @@
             "page": "fpd_rubicon_site_page"
           },
           "ext": {
-            "prebid": {
-              "data": {
-                "eidpermissions": null
-              }
-            }
+            "prebid": {}
           }
         }
       }
     }
   }
-
 }
\ No newline at end of file
diff --git a/exchange/exchangetest/passthrough_imp_only.json b/exchange/exchangetest/passthrough_imp_only.json
index 84e1a72b..e389a213 100644
--- a/exchange/exchangetest/passthrough_imp_only.json
+++ b/exchange/exchangetest/passthrough_imp_only.json
@@ -51,11 +51,6 @@
                         "ext": {
                             "bidder": {
                                 "placementId": 1
-                            },
-                            "prebid": {
-                                "passthrough": {
-                                    "imp_passthrough_val": 20
-                                }
                             }
                         }
                     },
diff --git a/exchange/exchangetest/passthrough_root_and_imp.json b/exchange/exchangetest/passthrough_root_and_imp.json
index d71bc5f2..423bad37 100644
--- a/exchange/exchangetest/passthrough_root_and_imp.json
+++ b/exchange/exchangetest/passthrough_root_and_imp.json
@@ -45,18 +45,11 @@
                         "ext": {
                             "bidder": {
                                 "placementId": 1
-                            },
-                            "prebid": {
-                                "passthrough": {
-                                    "imp_passthrough_val": 20
-                                }
                             }
                         }
                     }],
                     "ext": {
-                        "prebid": {
-                            "passthrough": {"bid_response_passthrough":20}
-                        }
+                        "prebid": {}
                     }
                 }
             },
diff --git a/exchange/exchangetest/passthrough_root_only.json b/exchange/exchangetest/passthrough_root_only.json
index 6b759e7a..c84f1927 100644
--- a/exchange/exchangetest/passthrough_root_only.json
+++ b/exchange/exchangetest/passthrough_root_only.json
@@ -44,9 +44,7 @@
                         }
                     }],
                     "ext": {
-                        "prebid": {
-                            "passthrough": {"bid_response_passthrough":20}
-                        }
+                        "prebid": {}
                     }
                 }
             },
diff --git a/exchange/exchangetest/request-ext-prebid-filtering.json b/exchange/exchangetest/request-ext-prebid-filtering.json
new file mode 100644
index 00000000..1d699c8a
--- /dev/null
+++ b/exchange/exchangetest/request-ext-prebid-filtering.json
@@ -0,0 +1,160 @@
+{
+    "description": "Verifies only allowed bid.request.ext.prebid values are passed to the bidder, leaving other ext fields untouched.",
+    "incomingRequest": {
+        "ortbRequest": {
+            "id": "test-request-id",
+            "site": {
+                "page": "test.testpage.com"
+            },
+            "imp": [
+                {
+                    "id": "imp-id",
+                    "video": {
+                        "mimes": [
+                            "video/mp4"
+                        ]
+                    },
+                    "ext": {
+                        "appnexus": {
+                            "placementId": 1
+                        }
+                    }
+                }
+            ],
+            "ext": {
+                "other": "test-other",
+                "prebid": {
+                    "data": {
+                        "eidpermissions": [
+                            {
+                                "source": "test-source",
+                                "bidders": [
+                                    "appnexus"
+                                ]
+                            }
+                        ]
+                    },
+                    "integration": "test-integration",
+                    "channel": {
+                        "name": "test-name",
+                        "version": "test-version"
+                    },
+                    "debug": true,
+                    "currency": {
+                        "rates": {
+                            "FOO": {
+                                "BAR": 42
+                            }
+                        },
+                        "usepbsrates": true
+                    },
+                    "bidderparams": {
+                        "appnexus": {
+                            "param1": 1,
+                            "paramA": "A"
+                        },
+                        "rubicon": {
+                            "not": "permitted-for-appnexus"
+                        }
+                    }
+                }
+            }
+        }
+    },
+    "outgoingRequests": {
+        "appnexus": {
+            "expectRequest": {
+                "ortbRequest": {
+                    "id": "test-request-id",
+                    "site": {
+                        "page": "test.testpage.com"
+                    },
+                    "imp": [
+                        {
+                            "id": "imp-id",
+                            "video": {
+                                "mimes": [
+                                    "video/mp4"
+                                ]
+                            },
+                            "ext": {
+                                "bidder": {
+                                    "placementId": 1
+                                }
+                            }
+                        }
+                    ],
+                    "ext": {
+                        "other": "test-other",
+                        "prebid": {
+                            "integration": "test-integration",
+                            "channel": {
+                                "name": "test-name",
+                                "version": "test-version"
+                            },
+                            "debug": true,
+                            "currency": {
+                                "rates": {
+                                    "FOO": {
+                                        "BAR": 42
+                                    }
+                                },
+                                "usepbsrates": true
+                            },
+                            "bidderparams": {
+                                "param1": 1,
+                                "paramA": "A"
+                            }
+                        }
+                    }
+                }
+            },
+            "mockResponse": {
+                "pbsSeatBids": [
+                    {
+                        "pbsBids": [
+                            {
+                                "ortbBid": {
+                                    "id": "apn-bid",
+                                    "impid": "imp-id",
+                                    "price": 0.3,
+                                    "w": 200,
+                                    "h": 250,
+                                    "crid": "creative-1"
+                                },
+                                "bidType": "video"
+                            }
+                        ],
+                        "seat": "appnexus"
+                    }
+                ]
+            }
+        }
+    },
+    "response": {
+        "bids": {
+            "id": "test-request-id",
+            "seatbid": [
+                {
+                    "seat": "appnexus",
+                    "bid": [
+                        {
+                            "id": "apn-bid",
+                            "impid": "imp-id",
+                            "price": 0.3,
+                            "w": 200,
+                            "h": 250,
+                            "crid": "creative-1",
+                            "ext": {
+                                "origbidcpm": 0.3,
+                                "prebid": {
+                                    "type": "video"
+                                }
+                            }
+                        }
+                    ]
+                }
+            ]
+        }
+    }
+}
\ No newline at end of file
diff --git a/exchange/exchangetest/request-imp-ext-prebid-filtering.json b/exchange/exchangetest/request-imp-ext-prebid-filtering.json
new file mode 100644
index 00000000..fb8e0892
--- /dev/null
+++ b/exchange/exchangetest/request-imp-ext-prebid-filtering.json
@@ -0,0 +1,136 @@
+{
+    "description": "Verifies only allowed bid.request.imp[].ext.prebid values are passed to the bidder, dropping other fields.",
+    "incomingRequest": {
+        "ortbRequest": {
+            "id": "test-request-id",
+            "site": {
+                "page": "test.testpage.com"
+            },
+            "imp": [
+                {
+                    "id": "imp-id",
+                    "video": {
+                        "mimes": [
+                            "video/mp4"
+                        ]
+                    },
+                    "ext": {
+                        "prebid": {
+                            "bidder": {
+                                "appnexus": {
+                                    "placementId": 1
+                                }
+                            },
+                            "storedrequest": {
+                                "id": "any-id"
+                            },
+                            "storedauctionresponse": {
+                                "id": "any-id"
+                            },
+                            "storedbidresponse": [
+                                {
+                                    "id": "any-id",
+                                    "bidder": "foo"
+                                }
+                            ],
+                            "is_rewarded_inventory": true,
+                            "options": {
+                                "echovideoattrs": true
+                            },
+                            "unknown": "any-unknown"
+                        },
+                        "data": "any-data",
+                        "context": "any-context",
+                        "skadn": "any-skadn",
+                        "gpid": "any-gpid",
+                        "tid": "any-tid"
+                    }
+                }
+            ]
+        }
+    },
+    "outgoingRequests": {
+        "appnexus": {
+            "expectRequest": {
+                "ortbRequest": {
+                    "id": "test-request-id",
+                    "site": {
+                        "page": "test.testpage.com"
+                    },
+                    "imp": [
+                        {
+                            "id": "imp-id",
+                            "video": {
+                                "mimes": [
+                                    "video/mp4"
+                                ]
+                            },
+                            "ext": {
+                                "bidder": {
+                                    "placementId": 1
+                                },
+                                "prebid": {
+                                    "is_rewarded_inventory": true,
+                                    "options": {
+                                        "echovideoattrs": true
+                                    }
+                                },
+                                "data": "any-data",
+                                "context": "any-context",
+                                "skadn": "any-skadn",
+                                "gpid": "any-gpid",
+                                "tid": "any-tid"
+                            }
+                        }
+                    ]
+                }
+            },
+            "mockResponse": {
+                "pbsSeatBids": [
+                    {
+                        "pbsBids": [
+                            {
+                                "ortbBid": {
+                                    "id": "apn-bid",
+                                    "impid": "imp-id",
+                                    "price": 0.3,
+                                    "w": 200,
+                                    "h": 250,
+                                    "crid": "creative-1"
+                                },
+                                "bidType": "video"
+                            }
+                        ],
+                        "seat": "appnexus"
+                    }
+                ]
+            }
+        }
+    },
+    "response": {
+        "bids": {
+            "id": "test-request-id",
+            "seatbid": [
+                {
+                    "seat": "appnexus",
+                    "bid": [
+                        {
+                            "id": "apn-bid",
+                            "impid": "imp-id",
+                            "price": 0.3,
+                            "w": 200,
+                            "h": 250,
+                            "crid": "creative-1",
+                            "ext": {
+                                "origbidcpm": 0.3,
+                                "prebid": {
+                                    "type": "video"
+                                }
+                            }
+                        }
+                    ]
+                }
+            ]
+        }
+    }
+}
\ No newline at end of file
diff --git a/exchange/exchangetest/schain-host-and-request.json b/exchange/exchangetest/schain-host-and-request.json
index 7a071124..88f407cd 100644
--- a/exchange/exchangetest/schain-host-and-request.json
+++ b/exchange/exchangetest/schain-host-and-request.json
@@ -6,33 +6,39 @@
             "site": {
                 "page": "test.somepage.com"
             },
-            "imp": [{
-                "id": "my-imp-id",
-                "video": {
-                    "mimes": ["video/mp4"]
-                },
-                "ext": {
-                    "appnexus": {
-                        "placementId": 1
+            "imp": [
+                {
+                    "id": "my-imp-id",
+                    "video": {
+                        "mimes": ["video/mp4"]
+                    },
+                    "ext": {
+                        "appnexus": {
+                            "placementId": 1
+                        }
                     }
                 }
-            }],
+            ],
             "ext": {
                 "prebid": {
                     "bidadjustmentfactors": null,
-                    "schains": [{
-                        "bidders": ["appnexus"],
-                        "schain": {
-                            "complete": 1,
-                            "nodes": [{
-                                "asi": "whatever.com",
-                                "sid": "1234",
-                                "rid": "123-456-7890",
-                                "hp": 1
-                            }],
-                            "ver": "2.0"
+                    "schains": [
+                        {
+                            "bidders": ["appnexus"],
+                            "schain": {
+                                "complete": 1,
+                                "nodes": [
+                                    {
+                                        "asi": "whatever.com",
+                                        "sid": "1234",
+                                        "rid": "123-456-7890",
+                                        "hp": 1
+                                    }
+                                ],
+                                "ver": "2.0"
+                            }
                         }
-                    }],
+                    ],
                     "debug": true,
                     "nosale": ["appnexus"]
                 }
@@ -47,21 +53,22 @@
                     "site": {
                         "page": "test.somepage.com"
                     },
-                    "imp": [{
-                        "id": "my-imp-id",
-                        "video": {
-                            "mimes": ["video/mp4"]
-                        },
-                        "ext": {
-                            "bidder": {
-                                "placementId": 1
+                    "imp": [
+                        {
+                            "id": "my-imp-id",
+                            "video": {
+                                "mimes": ["video/mp4"]
+                            },
+                            "ext": {
+                                "bidder": {
+                                    "placementId": 1
+                                }
                             }
                         }
-                    }],
+                    ],
                     "ext": {
                         "prebid": {
-                            "debug": true,
-                            "nosale": ["appnexus"]
+                            "debug": true
                         }
                     },
                     "source": {
@@ -69,21 +76,21 @@
                             "schain": {
                                 "complete": 1,
                                 "nodes": [
-                                  {
-                                    "asi": "whatever.com",
-                                    "sid": "1234",
-                                    "rid": "123-456-7890",
-                                    "hp": 1
-                                  },
-                                  {
-                                    "asi": "pbshostcompany.com",
-                                    "sid": "00001",
-                                    "rid": "BidRequest",
-                                    "hp": 1
-                                  }
+                                    {
+                                        "asi": "whatever.com",
+                                        "sid": "1234",
+                                        "rid": "123-456-7890",
+                                        "hp": 1
+                                    },
+                                    {
+                                        "asi": "pbshostcompany.com",
+                                        "sid": "00001",
+                                        "rid": "BidRequest",
+                                        "hp": 1
+                                    }
                                 ],
                                 "ver": "2.0"
-                              }
+                            }
                         }
                     }
                 },
diff --git a/exchange/exchangetest/schain-host-only.json b/exchange/exchangetest/schain-host-only.json
index 1750a8b4..d58947e3 100644
--- a/exchange/exchangetest/schain-host-only.json
+++ b/exchange/exchangetest/schain-host-only.json
@@ -6,17 +6,19 @@
             "site": {
                 "page": "test.somepage.com"
             },
-            "imp": [{
-                "id": "my-imp-id",
-                "video": {
-                    "mimes": ["video/mp4"]
-                },
-                "ext": {
-                    "appnexus": {
-                        "placementId": 1
+            "imp": [
+                {
+                    "id": "my-imp-id",
+                    "video": {
+                        "mimes": ["video/mp4"]
+                    },
+                    "ext": {
+                        "appnexus": {
+                            "placementId": 1
+                        }
                     }
                 }
-            }],
+            ],
             "ext": {
                 "prebid": {
                     "debug": true,
@@ -33,21 +35,22 @@
                     "site": {
                         "page": "test.somepage.com"
                     },
-                    "imp": [{
-                        "id": "my-imp-id",
-                        "video": {
-                            "mimes": ["video/mp4"]
-                        },
-                        "ext": {
-                            "bidder": {
-                                "placementId": 1
+                    "imp": [
+                        {
+                            "id": "my-imp-id",
+                            "video": {
+                                "mimes": ["video/mp4"]
+                            },
+                            "ext": {
+                                "bidder": {
+                                    "placementId": 1
+                                }
                             }
                         }
-                    }],
+                    ],
                     "ext": {
                         "prebid": {
-                            "debug": true,
-                            "nosale": ["appnexus"]
+                            "debug": true
                         }
                     },
                     "source": {
@@ -55,15 +58,15 @@
                             "schain": {
                                 "complete": 0,
                                 "nodes": [
-                                  {
-                                    "asi": "pbshostcompany.com",
-                                    "sid": "00001",
-                                    "rid": "BidRequest",
-                                    "hp": 1
-                                  }
+                                    {
+                                        "asi": "pbshostcompany.com",
+                                        "sid": "00001",
+                                        "rid": "BidRequest",
+                                        "hp": 1
+                                    }
                                 ],
                                 "ver": "1.0"
-                              }
+                            }
                         }
                     }
                 },
diff --git a/exchange/exchangetest/tricky-userids.json b/exchange/exchangetest/tricky-userids.json
index e01f53c7..065ec812 100644
--- a/exchange/exchangetest/tricky-userids.json
+++ b/exchange/exchangetest/tricky-userids.json
@@ -73,11 +73,7 @@
             }
           ],
           "ext": {
-            "prebid": {
-              "aliases": {
-                "districtm": "appnexus"
-              }
-            }
+            "prebid": {}
           }
         }
       },
@@ -111,11 +107,7 @@
             }
           ],
           "ext": {
-            "prebid": {
-              "aliases": {
-                "districtm": "appnexus"
-              }
-            }
+            "prebid": {}
           }
         }
       },
@@ -147,11 +139,7 @@
             }
           ],
           "ext": {
-            "prebid": {
-              "aliases": {
-                "districtm": "appnexus"
-              }
-            }
+            "prebid": {}
           }
         }
       },
diff --git a/exchange/utils_test.go b/exchange/utils_test.go
index 600d0721..4ff2aa0a 100644
--- a/exchange/utils_test.go
+++ b/exchange/utils_test.go
@@ -265,13 +265,14 @@ func TestCreateSanitizedImpExt(t *testing.T) {
 			expectedError:     "",
 		},
 		{
-			description: "imp.ext.prebid - Bidders Only",
+			description: "imp.ext.prebid - Bidder Only",
 			givenImpExt: map[string]json.RawMessage{
 				"prebid":  json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
 				"data":    json.RawMessage(`"anyData"`),
 				"context": json.RawMessage(`"anyContext"`),
 				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
 				"gpid":    json.RawMessage(`"anyGPID"`),
+				"tid":     json.RawMessage(`"anyTID"`),
 			},
 			givenImpExtPrebid: map[string]json.RawMessage{
 				"bidder": json.RawMessage(`"anyBidder"`),
@@ -281,28 +282,55 @@ func TestCreateSanitizedImpExt(t *testing.T) {
 				"context": json.RawMessage(`"anyContext"`),
 				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
 				"gpid":    json.RawMessage(`"anyGPID"`),
+				"tid":     json.RawMessage(`"anyTID"`),
 			},
 			expectedError: "",
 		},
 		{
-			description: "imp.ext.prebid - Bidders + Other Values",
+			description: "imp.ext.prebid - Bidder + Other Forbidden Value",
 			givenImpExt: map[string]json.RawMessage{
 				"prebid":  json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
 				"data":    json.RawMessage(`"anyData"`),
 				"context": json.RawMessage(`"anyContext"`),
 				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
 				"gpid":    json.RawMessage(`"anyGPID"`),
+				"tid":     json.RawMessage(`"anyTID"`),
 			},
 			givenImpExtPrebid: map[string]json.RawMessage{
 				"bidder":    json.RawMessage(`"anyBidder"`),
-				"someOther": json.RawMessage(`"value"`),
+				"forbidden": json.RawMessage(`"anyValue"`),
 			},
 			expected: map[string]json.RawMessage{
-				"prebid":  json.RawMessage(`{"someOther":"value"}`),
 				"data":    json.RawMessage(`"anyData"`),
 				"context": json.RawMessage(`"anyContext"`),
 				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
 				"gpid":    json.RawMessage(`"anyGPID"`),
+				"tid":     json.RawMessage(`"anyTID"`),
+			},
+			expectedError: "",
+		},
+		{
+			description: "imp.ext.prebid - Bidder + Other Allowed Values",
+			givenImpExt: map[string]json.RawMessage{
+				"prebid":  json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
+				"data":    json.RawMessage(`"anyData"`),
+				"context": json.RawMessage(`"anyContext"`),
+				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
+				"gpid":    json.RawMessage(`"anyGPID"`),
+				"tid":     json.RawMessage(`"anyTID"`),
+			},
+			givenImpExtPrebid: map[string]json.RawMessage{
+				"bidder":                json.RawMessage(`"anyBidder"`),
+				"is_rewarded_inventory": json.RawMessage(`"anyIsRewardedInventory"`),
+				"options":               json.RawMessage(`"anyOptions"`),
+			},
+			expected: map[string]json.RawMessage{
+				"prebid":  json.RawMessage(`{"is_rewarded_inventory":"anyIsRewardedInventory","options":"anyOptions"}`),
+				"data":    json.RawMessage(`"anyData"`),
+				"context": json.RawMessage(`"anyContext"`),
+				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
+				"gpid":    json.RawMessage(`"anyGPID"`),
+				"tid":     json.RawMessage(`"anyTID"`),
 			},
 			expectedError: "",
 		},
@@ -314,6 +342,7 @@ func TestCreateSanitizedImpExt(t *testing.T) {
 				"context":   json.RawMessage(`"anyContext"`),
 				"skadn":     json.RawMessage(`"anySKAdNetwork"`),
 				"gpid":      json.RawMessage(`"anyGPID"`),
+				"tid":       json.RawMessage(`"anyTID"`),
 			},
 			givenImpExtPrebid: map[string]json.RawMessage{},
 			expected: map[string]json.RawMessage{
@@ -321,11 +350,12 @@ func TestCreateSanitizedImpExt(t *testing.T) {
 				"context": json.RawMessage(`"anyContext"`),
 				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
 				"gpid":    json.RawMessage(`"anyGPID"`),
+				"tid":     json.RawMessage(`"anyTID"`),
 			},
 			expectedError: "",
 		},
 		{
-			description: "imp.ext + imp.ext.prebid - Prebid Bidders Only",
+			description: "imp.ext + imp.ext.prebid - Prebid Bidder Only",
 			givenImpExt: map[string]json.RawMessage{
 				"anyBidder": json.RawMessage(`"anyBidderValues"`),
 				"prebid":    json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
@@ -333,6 +363,7 @@ func TestCreateSanitizedImpExt(t *testing.T) {
 				"context":   json.RawMessage(`"anyContext"`),
 				"skadn":     json.RawMessage(`"anySKAdNetwork"`),
 				"gpid":      json.RawMessage(`"anyGPID"`),
+				"tid":       json.RawMessage(`"anyTID"`),
 			},
 			givenImpExtPrebid: map[string]json.RawMessage{
 				"bidder": json.RawMessage(`"anyBidder"`),
@@ -342,11 +373,12 @@ func TestCreateSanitizedImpExt(t *testing.T) {
 				"context": json.RawMessage(`"anyContext"`),
 				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
 				"gpid":    json.RawMessage(`"anyGPID"`),
+				"tid":     json.RawMessage(`"anyTID"`),
 			},
 			expectedError: "",
 		},
 		{
-			description: "imp.ext + imp.ext.prebid - Prebid Bidders + Other Values",
+			description: "imp.ext + imp.ext.prebid - Prebid Bidder + Other Forbidden Value",
 			givenImpExt: map[string]json.RawMessage{
 				"anyBidder": json.RawMessage(`"anyBidderValues"`),
 				"prebid":    json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
@@ -358,10 +390,35 @@ func TestCreateSanitizedImpExt(t *testing.T) {
 			},
 			givenImpExtPrebid: map[string]json.RawMessage{
 				"bidder":    json.RawMessage(`"anyBidder"`),
-				"someOther": json.RawMessage(`"value"`),
+				"forbidden": json.RawMessage(`"anyValue"`),
+			},
+			expected: map[string]json.RawMessage{
+				"data":    json.RawMessage(`"anyData"`),
+				"context": json.RawMessage(`"anyContext"`),
+				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
+				"gpid":    json.RawMessage(`"anyGPID"`),
+				"tid":     json.RawMessage(`"anyTID"`),
+			},
+			expectedError: "",
+		},
+		{
+			description: "imp.ext + imp.ext.prebid - Prebid Bidder + Other Allowed Values",
+			givenImpExt: map[string]json.RawMessage{
+				"anyBidder": json.RawMessage(`"anyBidderValues"`),
+				"prebid":    json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
+				"data":      json.RawMessage(`"anyData"`),
+				"context":   json.RawMessage(`"anyContext"`),
+				"skadn":     json.RawMessage(`"anySKAdNetwork"`),
+				"gpid":      json.RawMessage(`"anyGPID"`),
+				"tid":       json.RawMessage(`"anyTID"`),
+			},
+			givenImpExtPrebid: map[string]json.RawMessage{
+				"bidder":                json.RawMessage(`"anyBidder"`),
+				"is_rewarded_inventory": json.RawMessage(`"anyIsRewardedInventory"`),
+				"options":               json.RawMessage(`"anyOptions"`),
 			},
 			expected: map[string]json.RawMessage{
-				"prebid":  json.RawMessage(`{"someOther":"value"}`),
+				"prebid":  json.RawMessage(`{"is_rewarded_inventory":"anyIsRewardedInventory","options":"anyOptions"}`),
 				"data":    json.RawMessage(`"anyData"`),
 				"context": json.RawMessage(`"anyContext"`),
 				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
@@ -378,12 +435,13 @@ func TestCreateSanitizedImpExt(t *testing.T) {
 				"context": json.RawMessage(`"anyContext"`),
 				"skadn":   json.RawMessage(`"anySKAdNetwork"`),
 				"gpid":    json.RawMessage(`"anyGPID"`),
+				"tid":     json.RawMessage(`"anyTID"`),
 			},
 			givenImpExtPrebid: map[string]json.RawMessage{
-				"malformed": json.RawMessage(`json`), // String value without quotes.
+				"options": json.RawMessage(`malformed`), // String value without quotes.
 			},
 			expected:      nil,
-			expectedError: "cannot marshal ext.prebid: json: error calling MarshalJSON for type json.RawMessage: invalid character 'j' looking for beginning of value",
+			expectedError: "cannot marshal ext.prebid: json: error calling MarshalJSON for type json.RawMessage: invalid character 'm' looking for beginning of value",
 		},
 	}
 
@@ -2382,6 +2440,99 @@ func TestCleanOpenRTBRequestsGDPRBlockBidRequest(t *testing.T) {
 	}
 }
 
+func TestBuildRequestExtForBidder(t *testing.T) {
+	bidder := "foo"
+	bidderParams := json.RawMessage(`"bar"`)
+
+	testCases := []struct {
+		description  string
+		requestExt   json.RawMessage
+		bidderParams map[string]json.RawMessage
+		expectedJson json.RawMessage
+	}{
+		{
+			description:  "Nil",
+			bidderParams: nil,
+			requestExt:   nil,
+			expectedJson: json.RawMessage(``),
+		},
+		{
+			description:  "Empty",
+			bidderParams: nil,
+			requestExt:   json.RawMessage(`{}`),
+			expectedJson: json.RawMessage(`{"prebid":{}}`),
+		},
+		{
+			description:  "Prebid - Allowed Fields Only",
+			bidderParams: nil,
+			requestExt:   json.RawMessage(`{"prebid":{"integration":"a","channel":{"name":"b","version":"c"},"debug":true,"currency":{"rates":{"FOO":{"BAR":42}},"usepbsrates":true}}}`),
+			expectedJson: json.RawMessage(`{"prebid":{"integration":"a","channel":{"name":"b","version":"c"},"debug":true,"currency":{"rates":{"FOO":{"BAR":42}},"usepbsrates":true}}}`),
+		},
+		{
+			description:  "Prebid - Allowed Fields + Bidder Params",
+			bidderParams: map[string]json.RawMessage{bidder: bidderParams},
+			requestExt:   json.RawMessage(`{"prebid":{"integration":"a","channel":{"name":"b","version":"c"},"debug":true,"currency":{"rates":{"FOO":{"BAR":42}},"usepbsrates":true}}}`),
+			expectedJson: json.RawMessage(`{"prebid":{"integration":"a","channel":{"name":"b","version":"c"},"debug":true,"currency":{"rates":{"FOO":{"BAR":42}},"usepbsrates":true},"bidderparams":"bar"}}`),
+		},
+		{
+			description:  "Other",
+			bidderParams: nil,
+			requestExt:   json.RawMessage(`{"other":"foo"}`),
+			expectedJson: json.RawMessage(`{"other":"foo","prebid":{}}`),
+		},
+		{
+			description:  "Prebid + Other + Bider Params",
+			bidderParams: map[string]json.RawMessage{bidder: bidderParams},
+			requestExt:   json.RawMessage(`{"other":"foo","prebid":{"integration":"a","channel":{"name":"b","version":"c"},"debug":true,"currency":{"rates":{"FOO":{"BAR":42}},"usepbsrates":true}}}`),
+			expectedJson: json.RawMessage(`{"other":"foo","prebid":{"integration":"a","channel":{"name":"b","version":"c"},"debug":true,"currency":{"rates":{"FOO":{"BAR":42}},"usepbsrates":true},"bidderparams":"bar"}}`),
+		},
+	}
+
+	for _, test := range testCases {
+		requestExtParsed := &openrtb_ext.ExtRequest{}
+		if test.requestExt != nil {
+			err := json.Unmarshal(test.requestExt, requestExtParsed)
+			if !assert.NoError(t, err, test.description+":parse_ext") {
+				continue
+			}
+		}
+
+		actualJson, actualErr := buildRequestExtForBidder(bidder, test.requestExt, requestExtParsed, test.bidderParams)
+		if len(test.expectedJson) > 0 {
+			assert.JSONEq(t, string(test.expectedJson), string(actualJson), test.description+":json")
+		} else {
+			assert.Equal(t, test.expectedJson, actualJson, test.description+":json")
+		}
+		assert.NoError(t, actualErr, test.description+":err")
+	}
+}
+
+func TestBuildRequestExtForBidder_RequestExtParsedNil(t *testing.T) {
+	var (
+		bidder           = "foo"
+		requestExt       = json.RawMessage(`{}`)
+		requestExtParsed *openrtb_ext.ExtRequest
+		bidderParams     map[string]json.RawMessage
+	)
+
+	actualJson, actualErr := buildRequestExtForBidder(bidder, requestExt, requestExtParsed, bidderParams)
+	assert.Equal(t, json.RawMessage(``), actualJson)
+	assert.NoError(t, actualErr)
+}
+
+func TestBuildRequestExtForBidder_RequestExtMalformed(t *testing.T) {
+	var (
+		bidder           = "foo"
+		requestExt       = json.RawMessage(`malformed`)
+		requestExtParsed = &openrtb_ext.ExtRequest{}
+		bidderParams     map[string]json.RawMessage
+	)
+
+	actualJson, actualErr := buildRequestExtForBidder(bidder, requestExt, requestExtParsed, bidderParams)
+	assert.Equal(t, json.RawMessage(nil), actualJson)
+	assert.EqualError(t, actualErr, "invalid character 'm' looking for beginning of value")
+}
+
 // newAdapterAliasBidRequest builds a BidRequest with aliases
 func newAdapterAliasBidRequest(t *testing.T) *openrtb2.BidRequest {
 	dnt := int8(1)