From 5adfab9dc9e5f81748fd8e83e0513593fe99acfa Mon Sep 17 00:00:00 2001 From: Tony Wu Date: Thu, 15 Jan 2026 16:13:47 -0800 Subject: [PATCH] Inject server ip --- endpoints/openrtb2/auction.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/endpoints/openrtb2/auction.go b/endpoints/openrtb2/auction.go index ee29584a61e..5257745a27e 100644 --- a/endpoints/openrtb2/auction.go +++ b/endpoints/openrtb2/auction.go @@ -196,6 +196,8 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http return } + injectServerIP(r, req, deps.privateNetworkIPValidator) + if rejectErr := hookexecution.FindFirstRejectOrNil(errL); rejectErr != nil { ao.RequestWrapper = req labels, ao = rejectAuctionRequest(*rejectErr, w, hookExecutor, req.BidRequest, account, labels, ao) @@ -2101,3 +2103,30 @@ func (deps *endpointDeps) processGDPR(req *openrtb_ext.RequestWrapper, accountGD return tcf2Config, gdprSignal, gdprEnforced, gdprErrs } + +func injectServerIP(httpReq *http.Request, r *openrtb_ext.RequestWrapper, ipValidator iputil.IPValidator) { + if ip, _ := httputil.FindIP(httpReq, ipValidator); ip != nil { + reqExt, err := r.GetRequestExt() + if err != nil { + return + } + extMap := reqExt.GetExt() + + var mspExt map[string]interface{} + if val, ok := extMap["msp"]; ok { + if err := json.Unmarshal(val, &mspExt); err != nil { + mspExt = make(map[string]interface{}) + } + } else { + mspExt = make(map[string]interface{}) + } + + mspExt["server_ip"] = ip.String() + + if mspBytes, err := json.Marshal(mspExt); err == nil { + extMap["msp"] = json.RawMessage(mspBytes) + reqExt.SetExt(extMap) + r.RebuildRequest() + } + } +}