-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scrubber refactoring #3108
Scrubber refactoring #3108
Changes from 12 commits
76c472e
571ae2a
b85dc81
330af18
edf120a
b4f9ad2
e25b154
8f3dd23
06c9e92
f3059c2
57e08ea
1ee688b
ea36a24
ea4a9e3
a836351
8d24ed7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"github.com/prebid/prebid-server/v2/gdpr" | ||
"github.com/prebid/prebid-server/v2/metrics" | ||
"github.com/prebid/prebid-server/v2/openrtb_ext" | ||
"github.com/prebid/prebid-server/v2/ortb" | ||
"github.com/prebid/prebid-server/v2/privacy" | ||
"github.com/prebid/prebid-server/v2/privacy/ccpa" | ||
"github.com/prebid/prebid-server/v2/privacy/lmt" | ||
|
@@ -153,11 +154,6 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context, | |
|
||
// bidder level privacy policies | ||
for _, bidderRequest := range allBidderRequests { | ||
privacyEnforcement := privacy.Enforcement{ | ||
COPPA: coppa, | ||
LMT: lmt, | ||
} | ||
|
||
// fetchBids activity | ||
scopedName := privacy.Component{Type: privacy.ComponentTypeBidder, Name: bidderRequest.BidderName.String()} | ||
fetchBidsActivityAllowed := auctionReq.Activities.Allow(privacy.ActivityFetchBids, scopedName, privacy.NewRequestFromBidRequest(*req)) | ||
|
@@ -180,46 +176,68 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context, | |
} | ||
} | ||
|
||
ipConf := privacy.IPConf{IPV6: auctionReq.Account.Privacy.IPv6Config, IPV4: auctionReq.Account.Privacy.IPv4Config} | ||
|
||
// FPD should be applied before policies, otherwise it overrides policies and activities restricted data | ||
applyFPD(auctionReq.FirstPartyData, bidderRequest) | ||
|
||
reqWrapper := cloneBidderReq(bidderRequest.BidRequest) | ||
|
||
passIDActivityAllowed := auctionReq.Activities.Allow(privacy.ActivityTransmitUserFPD, scopedName, privacy.NewRequestFromBidRequest(*req)) | ||
if !passIDActivityAllowed { | ||
privacyEnforcement.UFPD = true | ||
//UFPD | ||
privacy.ScrubUserFPD(reqWrapper) | ||
} else { | ||
// run existing policies (GDPR, CCPA, COPPA, LMT) | ||
// potentially block passing IDs based on GDPR | ||
if gdprEnforced { | ||
if gdprErr == nil { | ||
privacyEnforcement.GDPRID = !auctionPermissions.PassID | ||
if !auctionPermissions.PassID { | ||
privacy.ScrubGdprID(reqWrapper) | ||
} | ||
} else { | ||
privacyEnforcement.GDPRID = true | ||
privacy.ScrubGdprID(reqWrapper) | ||
} | ||
} | ||
// potentially block passing IDs based on CCPA | ||
privacyEnforcement.CCPA = ccpaEnforcer.ShouldEnforce(bidderRequest.BidderName.String()) | ||
if ccpaEnforcer.ShouldEnforce(bidderRequest.BidderName.String()) { | ||
privacy.ScrubDeviceIDsIPsUserDemoExt(reqWrapper, ipConf, "eids", false) | ||
} | ||
} | ||
|
||
passGeoActivityAllowed := auctionReq.Activities.Allow(privacy.ActivityTransmitPreciseGeo, scopedName, privacy.NewRequestFromBidRequest(*req)) | ||
if !passGeoActivityAllowed { | ||
privacyEnforcement.PreciseGeo = true | ||
privacy.ScrubGeoAndDeviceIP(reqWrapper, ipConf) | ||
} else { | ||
// run existing policies (GDPR, CCPA, COPPA, LMT) | ||
// potentially block passing geo based on GDPR | ||
if gdprEnforced { | ||
if gdprErr == nil { | ||
privacyEnforcement.GDPRGeo = !auctionPermissions.PassGeo | ||
if !auctionPermissions.PassGeo { | ||
privacy.ScrubGeoAndDeviceIP(reqWrapper, ipConf) | ||
} | ||
} else { | ||
privacyEnforcement.GDPRGeo = true | ||
privacy.ScrubGeoAndDeviceIP(reqWrapper, ipConf) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be simplified to:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored |
||
} | ||
// potentially block passing geo based on CCPA | ||
privacyEnforcement.CCPA = ccpaEnforcer.ShouldEnforce(bidderRequest.BidderName.String()) | ||
if ccpaEnforcer.ShouldEnforce(bidderRequest.BidderName.String()) { | ||
privacy.ScrubDeviceIDsIPsUserDemoExt(reqWrapper, ipConf, "eids", false) | ||
} | ||
} | ||
|
||
if lmt || coppa { | ||
privacy.ScrubDeviceIDsIPsUserDemoExt(reqWrapper, ipConf, "eids", coppa) | ||
} | ||
|
||
applyFPD(auctionReq.FirstPartyData, bidderRequest) | ||
passTIDAllowed := auctionReq.Activities.Allow(privacy.ActivityTransmitTIDs, scopedName, privacy.NewRequestFromBidRequest(*req)) | ||
if !passTIDAllowed { | ||
privacy.ScrubTID(reqWrapper) | ||
} | ||
|
||
privacyEnforcement.TID = !auctionReq.Activities.Allow(privacy.ActivityTransmitTIDs, scopedName, privacy.NewRequestFromBidRequest(*req)) | ||
reqWrapper.RebuildRequest() | ||
bidderRequest.BidRequest = reqWrapper.BidRequest | ||
|
||
privacyEnforcement.Apply(bidderRequest.BidRequest, auctionReq.Account.Privacy) | ||
allowedBidderRequests = append(allowedBidderRequests, bidderRequest) | ||
|
||
// GPP downgrade: always downgrade unless we can confirm GPP is supported | ||
|
@@ -232,6 +250,34 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context, | |
return | ||
} | ||
|
||
// cloneBidderReq - clones bidder request and replaces req.User and req.Device with new copies | ||
func cloneBidderReq(req *openrtb2.BidRequest) *openrtb_ext.RequestWrapper { | ||
|
||
// bidder request may be modified differently per bidder based on privacy configs | ||
// new request should be created for each bidder request | ||
// pointer fields like User and Device should be cloned and set back to the request copy | ||
var newReq *openrtb2.BidRequest | ||
newReq = ptrutil.Clone(req) | ||
Comment on lines
+247
to
+248
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can these lines be rewritten as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be, yes, but IDE will miss the variable type (because it's generic after Clone) and underlines follow up code to red. We discussed it in one of the previous PRs. It's ok to leave the variable instantiation, it doesn't take memory and CPU and makes IDE happy. |
||
|
||
if req.User != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
userCopy := ortb.CloneUser(req.User) | ||
newReq.User = userCopy | ||
} | ||
|
||
if req.Device != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clone functions added |
||
deviceCopy := ortb.CloneDevice(req.Device) | ||
newReq.Device = deviceCopy | ||
} | ||
|
||
if req.Source != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add |
||
sourceCopy := ortb.CloneSource(req.Source) | ||
newReq.Source = sourceCopy | ||
} | ||
|
||
reqWrapper := &openrtb_ext.RequestWrapper{BidRequest: newReq} | ||
return reqWrapper | ||
} | ||
|
||
func shouldSetLegacyPrivacy(bidderInfo config.BidderInfos, bidder string) bool { | ||
binfo, defined := bidderInfo[bidder] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be simplified to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I also combined it with the previous if statement.