Skip to content
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

Flipp: abide by privacy concerns when using flippExt userKey #3250

Merged
merged 6 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions adapters/flipp/flipp.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package flipp

import (
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"

"github.com/buger/jsonparser"
"github.com/gofrs/uuid"
"github.com/prebid/go-gdpr/consentconstants"
"github.com/prebid/go-gdpr/vendorconsent"
"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/uuidutil"
)

const (
Expand All @@ -22,6 +25,8 @@ const (
defaultCurrency = "USD"
)

var uuidGenerator uuidutil.UUIDGenerator

var (
count int64 = 1
adTypes = []int64{4309, 641}
Expand All @@ -34,6 +39,7 @@ type adapter struct {

// Builder builds a new instance of the Flipp adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
uuidGenerator = uuidutil.UUIDRandomGenerator{}
bidder := &adapter{
endpoint: config.Endpoint,
}
Expand Down Expand Up @@ -123,14 +129,15 @@ func (a *adapter) processImp(request *openrtb2.BidRequest, imp openrtb2.Imp) (*a
var userKey string
if request.User != nil && request.User.ID != "" {
userKey = request.User.ID
} else if flippExtParams.UserKey != "" {
} else if flippExtParams.UserKey != "" && paramsUserKeyPermitted(request) {
userKey = flippExtParams.UserKey
onkarvhanumante marked this conversation as resolved.
Show resolved Hide resolved
} else {
uid, err := uuid.NewV4()

uid, err := uuidGenerator.Generate()
if err != nil {
return nil, fmt.Errorf("unable to generate user uuid. %v", err)
}
userKey = uid.String()
userKey = uid
}

keywordsArray := strings.Split(request.Site.Keywords, ",")
Expand Down Expand Up @@ -223,3 +230,38 @@ func buildBid(decision *InlineModel, impId string) *openrtb2.Bid {
}
return bid
}

func paramsUserKeyPermitted(request *openrtb2.BidRequest) bool {
if request.Regs != nil {
if request.Regs.COPPA == 1 {
return false
}
if request.Regs.GDPR != nil && *request.Regs.GDPR == 1 {
return false
}
}
if request.Ext != nil {
var extData struct {
TransmitEids *bool `json:"transmitEids,omitempty"`
}
if err := json.Unmarshal(request.Ext, &extData); err == nil {
if extData.TransmitEids != nil && !*extData.TransmitEids {
return false
}
}
}
if request.User != nil && request.User.Consent != "" {
data, err := base64.RawURLEncoding.DecodeString(request.User.Consent)
if err != nil {
return true
}
consent, err := vendorconsent.Parse(data)
if err != nil {
return true
}
if !consent.PurposeAllowed(consentconstants.ContentSelectionDeliveryReporting) {
return false
}
onkarvhanumante marked this conversation as resolved.
Show resolved Hide resolved
}
return true
}
54 changes: 54 additions & 0 deletions adapters/flipp/flipp_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,75 @@
package flipp

import (
"encoding/json"
"testing"

"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/v2/adapters/adapterstest"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/stretchr/testify/assert"
)

const fakeUuid = "30470a14-2949-4110-abce-b62d57304ad5"

type TestUUIDGenerator struct{}

func (TestUUIDGenerator) Generate() (string, error) {
return fakeUuid, nil
}

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderFlipp, config.Adapter{
Endpoint: "http://example.com/pserver"},
config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
uuidGenerator = TestUUIDGenerator{}

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}

adapterstest.RunJSONBidderTest(t, "flipptest", bidder)
}

func TestParamsUserKeyPermitted(t *testing.T) {

t.Run("Coppa is in effect", func(t *testing.T) {
request := &openrtb2.BidRequest{
Regs: &openrtb2.Regs{
COPPA: 1,
},
}
result := paramsUserKeyPermitted(request)
assert.New(t)
assert.False(t, result, "param user key not permitted because coppa is in effect")
})
t.Run("The Global Privacy Control is set", func(t *testing.T) {
request := &openrtb2.BidRequest{
Regs: &openrtb2.Regs{
GDPR: openrtb2.Int8Ptr(1),
},
}
result := paramsUserKeyPermitted(request)
assert.New(t)
assert.False(t, result, "param user key not permitted because Global Privacy Control is set")
})
t.Run("The Prebid transmitEids activity is disallowed", func(t *testing.T) {
extData := struct {
TransmitEids bool `json:"transmitEids"`
}{
TransmitEids: false,
}
ext, err := json.Marshal(extData)
if err != nil {
t.Fatalf("failed to marshal ext data: %v", err)
}
request := &openrtb2.BidRequest{
Ext: ext,
}

result := paramsUserKeyPermitted(request)
assert.New(t)
assert.False(t, result, "param user key not permitted because Prebid transmitEids activity is disallowed")
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
{
"mockBidRequest": {
"id": "test-request-id",
"test": 1,
"device": {
"ip": "123.123.123.123"
},
"site": {
"id": "1243066",
"page": "http://www.example.com/test?flipp-content-code=publisher-test"
},
"user": {
},
"ext": {
"transmitEids": false
},
"regs": {
"coppa": 0,
"gdpr": 0
},
"imp": [
{
"id": "test-imp-id",
"tagid": "test",
"banner": {
"format": [
{
"w": 300,
"h": 1800
}
]
},
"ext": {
"bidder": {
"publisherNameIdentifier": "wishabi-test-publisher",
"creativeType": "NativeX",
"siteId": 1243066,
"zoneIds": [285431],
"options": {
"startCompact": true
},
"userKey": "abc123"
}
}
}

]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com/pserver",
"body": {
"ip":"123.123.123.123",
"keywords":[
""
],
"placements":[
{
"adTypes":[
4309,
641
],
"count":1,
"divName":"inline",
"prebid":{
"creativeType":"NativeX",
"height":1800,
"publisherNameIdentifier":"wishabi-test-publisher",
"requestId":"test-imp-id",
"width":300
},
"properties":{
"contentCode":"publisher-test"
},
"siteId":1243066,
"zoneIds":[
285431
],
"options": {
"startCompact": true
}
}
],
"url":"http://www.example.com/test?flipp-content-code=publisher-test",
"user":{
"key":"30470a14-2949-4110-abce-b62d57304ad5"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"decisions": {
"inline": [
{
"adId": 183599115,
"advertiserId": 1988027,
"campaignId": 63285392,
"clickUrl": "https://e-11090.adzerk.net/r?e=eyJ2IjoiMS4xMSIsImF2IjoxOTg4MDI3LCJhdCI6NDMwOSwiYnQiOjAsImNtIjo2MzI4NTM5MiwiY2giOjU4MDgxLCJjayI6e30sImNyIjo4MTMyNTY5MCwiZGkiOiJiOTg3MGNkYTA5MTU0NDlmOTkwZGNkZTNmNjYyNGNhMyIsImRqIjowLCJpaSI6IjJmNjYwMjMyODBmYjQ4NTRiYTY0YzFlYzA1ZDU5MTNiIiwiZG0iOjMsImZjIjoxODM1OTkxMTUsImZsIjoxNzU0MjE3OTUsImlwIjoiMTQyLjE4MS41OC41MiIsIm53IjoxMDkyMiwicGMiOjAsIm9wIjowLCJlYyI6MCwiZ20iOjAsImVwIjpudWxsLCJwciI6MjMyNjk5LCJydCI6MywicnMiOjUwMCwic2EiOiIzNCIsInNiIjoiaS0wNDZjMWNlNWRjYmExMTVjNSIsInNwIjozNzIzMDU1LCJzdCI6MTI0MzA2NiwidWsiOiJkOTU1N2Q2NS1kNWI5LTQyOTItYjg2My0xNGEyOTcyNTk3ZjQiLCJ6biI6Mjg1NDMxLCJ0cyI6MTY4MDU1NTc4MzkyMiwicG4iOiJpbmxpbmUiLCJnYyI6dHJ1ZSwiZ0MiOnRydWUsImdzIjoibm9uZSIsInR6IjoiQW1lcmljYS9OZXdfWW9yayIsInVyIjoiaHR0cDovL3d3dy5mbGlwcC5jb20ifQ&s=Mnss8P1kc37Eftik5RJvLJb4S9Y",
"contents": [
{
"data": {
"customData": {
"campaignConfigUrl": "https://campaign-config.flipp.com/dist-campaign-admin/215",
"campaignNameIdentifier": "US Grocery Demo (Kroger)"
},
"height": 1800,
"width": 300
},
"type": "raw"
}
],
"creativeId": 81325690,
"flightId": 175421795,
"height": 1800,
"impressionUrl": "https://e-11090.adzerk.net/i.gif?e=eyJ2IjoiMS4xMSIsImF2IjoxOTg4MDI3LCJhdCI6NDMwOSwiYnQiOjAsImNtIjo2MzI4NTM5MiwiY2giOjU4MDgxLCJjayI6e30sImNyIjo4MTMyNTY5MCwiZGkiOiJiOTg3MGNkYTA5MTU0NDlmOTkwZGNkZTNmNjYyNGNhMyIsImRqIjowLCJpaSI6IjJmNjYwMjMyODBmYjQ4NTRiYTY0YzFlYzA1ZDU5MTNiIiwiZG0iOjMsImZjIjoxODM1OTkxMTUsImZsIjoxNzU0MjE3OTUsImlwIjoiMTQyLjE4MS41OC41MiIsIm53IjoxMDkyMiwicGMiOjAsIm9wIjowLCJlYyI6MCwiZ20iOjAsImVwIjpudWxsLCJwciI6MjMyNjk5LCJydCI6MywicnMiOjUwMCwic2EiOiIzNCIsInNiIjoiaS0wNDZjMWNlNWRjYmExMTVjNSIsInNwIjozNzIzMDU1LCJzdCI6MTI0MzA2NiwidWsiOiJkOTU1N2Q2NS1kNWI5LTQyOTItYjg2My0xNGEyOTcyNTk3ZjQiLCJ6biI6Mjg1NDMxLCJ0cyI6MTY4MDU1NTc4MzkyMywicG4iOiJpbmxpbmUiLCJnYyI6dHJ1ZSwiZ0MiOnRydWUsImdzIjoibm9uZSIsInR6IjoiQW1lcmljYS9OZXdfWW9yayIsImJhIjoxLCJmcSI6MH0&s=Qce4_IohtESeNA_sB71Qjb4TouY",
"prebid": {
"cpm": 12.34,
"creative":"creativeContent",
"creativeType": "NativeX",
"requestId": "test-imp-id"
},
"priorityId": 232699,
"storefront": {
"campaignConfig": {
"fallbackImageUrl": "https://f.wishabi.net/arbitrary_files/115856/1666018811/115856_Featured Local Savings - Flipp Fallback - US (1).png",
"fallbackLinkUrl": "https://flipp.com/flyers/",
"tags": {
"advertiser": {
"engagement": "https://f.wishabi.net/creative/happyfruits/_itemlevelv2/apple.png?cb=[[random]]"
}
}
},
"flyer_id": 5554080,
"flyer_run_id": 873256,
"flyer_type_id": 2826,
"is_fallback": true,
"merchant": "Kroger",
"merchant_id": 2778,
"name": "Weekly Ad",
"storefront_logo_url": "https://images.wishabi.net/merchants/qX1/BGIzc9sFcA==/RackMultipart20210421-1-e3k5rx.jpeg",
"storefront_payload_url": "https://cdn-gateflipp.flippback.com/storefront-payload/v2/873256/5554080/ff14f675705934507c269b5750e124a323bc9bf60e8a6f210f422f4528b233ff?merchant_id=2778",
"valid_from": "2023-03-29 04:00:00 +0000 UTC",
"valid_to": "2023-04-05 03:59:59 +0000 UTC"
},
"width": 300
}
]
},
"location": {
"accuracy_radius": 5,
"city": "Toronto",
"country": "CA",
"ip": "123.123.123.123",
"postal_code": "M4S",
"region": "ON",
"region_name": "Ontario"
}
}
}
}
],
"expectedBidResponses": [
{
"bids": [
{
"bid": {
"id": "183599115",
"impid": "test-imp-id",
"price": 12.34,
"adm": "creativeContent",
"crid": "81325690",
"w": 300
},
"type": "banner"
}
]
}
]
}
Loading
Loading