Skip to content

Commit

Permalink
UOE-6121: Reverting changes for sec flag for uids cookie (#122)
Browse files Browse the repository at this point in the history
* UOE-6121: Reverting changes for sec flag for uids cookie

* Fixed tests and always setting secure flag

* Fixed Ix usersync url
  • Loading branch information
sachin-pubmatic authored Mar 3, 2021
1 parent 65c04f5 commit d7e2a8c
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 305 deletions.
2 changes: 1 addition & 1 deletion adapters/adform/adform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func preparePrebidRequest(serverUrl string, t *testing.T) *pbs.PBSRequest {
pbsCookie.TrySync("adform", adformTestData.buyerUID)
fakeWriter := httptest.NewRecorder()

pbsCookie.SetCookieOnResponse(fakeWriter, false, "", &config.HostCookie{Domain: ""}, time.Minute)
pbsCookie.SetCookieOnResponse(fakeWriter, false, &config.HostCookie{Domain: ""}, time.Minute)
prebidHttpRequest.Header.Add("Cookie", fakeWriter.Header().Get("Set-Cookie"))

cacheClient, _ := dummycache.New()
Expand Down
2 changes: 1 addition & 1 deletion adapters/appnexus/appnexus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func TestAppNexusLegacyBasicResponse(t *testing.T) {
pc.TrySync("adnxs", andata.buyerUID)
fakewriter := httptest.NewRecorder()

pc.SetCookieOnResponse(fakewriter, false, "", &config.HostCookie{Domain: ""}, 90*24*time.Hour)
pc.SetCookieOnResponse(fakewriter, false, &config.HostCookie{Domain: ""}, 90*24*time.Hour)
req.Header.Add("Cookie", fakewriter.Header().Get("Set-Cookie"))

cacheClient, _ := dummycache.New()
Expand Down
2 changes: 1 addition & 1 deletion adapters/lifestreet/lifestreet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func TestLifestreetBasicResponse(t *testing.T) {
pc := usersync.ParsePBSCookieFromRequest(req, &config.HostCookie{})
fakewriter := httptest.NewRecorder()

pc.SetCookieOnResponse(fakewriter, false, "", &config.HostCookie{Domain: ""}, 90*24*time.Hour)
pc.SetCookieOnResponse(fakewriter, false, &config.HostCookie{Domain: ""}, 90*24*time.Hour)
req.Header.Add("Cookie", fakewriter.Header().Get("Set-Cookie"))

cacheClient, _ := dummycache.New()
Expand Down
2 changes: 1 addition & 1 deletion adapters/pubmatic/pubmatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func TestPubmaticSampleRequest(t *testing.T) {
pc.TrySync("pubmatic", "12345")
fakewriter := httptest.NewRecorder()

pc.SetCookieOnResponse(fakewriter, false, "", &config.HostCookie{Domain: ""}, 90*24*time.Hour)
pc.SetCookieOnResponse(fakewriter, false, &config.HostCookie{Domain: ""}, 90*24*time.Hour)
httpReq.Header.Add("Cookie", fakewriter.Header().Get("Set-Cookie"))

cacheClient, _ := dummycache.New()
Expand Down
2 changes: 1 addition & 1 deletion adapters/pulsepoint/pulsepoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func SampleRequest(numberOfImpressions int, t *testing.T) *pbs.PBSRequest {
pc.TrySync("pulsepoint", "pulsepointUser123")
fakewriter := httptest.NewRecorder()

pc.SetCookieOnResponse(fakewriter, false, "", &config.HostCookie{Domain: ""}, 90*24*time.Hour)
pc.SetCookieOnResponse(fakewriter, false, &config.HostCookie{Domain: ""}, 90*24*time.Hour)
httpReq.Header.Add("Cookie", fakewriter.Header().Get("Set-Cookie"))
// parse the http request
cacheClient, _ := dummycache.New()
Expand Down
2 changes: 1 addition & 1 deletion adapters/rubicon/rubicon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ func CreatePrebidRequest(server *httptest.Server, t *testing.T) (an *RubiconAdap
pc.TrySync("rubicon", rubidata.buyerUID)
fakewriter := httptest.NewRecorder()

pc.SetCookieOnResponse(fakewriter, false, "", &config.HostCookie{Domain: ""}, 90*24*time.Hour)
pc.SetCookieOnResponse(fakewriter, false, &config.HostCookie{Domain: ""}, 90*24*time.Hour)
req.Header.Add("Cookie", fakewriter.Header().Get("Set-Cookie"))

cacheClient, _ := dummycache.New()
Expand Down
2 changes: 1 addition & 1 deletion adapters/sovrn/sovrn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func SampleSovrnRequest(numberOfImpressions int, t *testing.T) *pbs.PBSRequest {
pc.TrySync("sovrn", testSovrnUserId)
fakewriter := httptest.NewRecorder()

pc.SetCookieOnResponse(fakewriter, false, "", &config.HostCookie{Domain: ""}, 90*24*time.Hour)
pc.SetCookieOnResponse(fakewriter, false, &config.HostCookie{Domain: ""}, 90*24*time.Hour)
httpReq.Header.Add("Cookie", fakewriter.Header().Get("Set-Cookie"))
// parse the http request
cacheClient, _ := dummycache.New()
Expand Down
139 changes: 68 additions & 71 deletions config/config.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func TestFullConfig(t *testing.T) {
cmpStrings(t, "adapters.brightroll.usersync_url", cfg.Adapters[string(openrtb_ext.BidderBrightroll)].UserSyncURL, "http://test-bh.ybp.yahoo.com/sync/appnexuspbs?gdpr={{.GDPR}}&euconsent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&url=%s")
cmpStrings(t, "adapters.adkerneladn.usersync_url", cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderAdkernelAdn))].UserSyncURL, "https://tag.adkernel.com/syncr?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&r=")
cmpStrings(t, "adapters.rhythmone.endpoint", cfg.Adapters[string(openrtb_ext.BidderRhythmone)].Endpoint, "http://tag.1rx.io/rmp")
cmpStrings(t, "adapters.rhythmone.usersync_url", cfg.Adapters[string(openrtb_ext.BidderRhythmone)].UserSyncURL, "https://sync.1rx.io/usersync2/rmphb?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redir=http%3A%2F%2Fprebid-server.prebid.org%2F%2Fsetuid%3Fsec%3D%7BSecParam%7D%26bidder%3Drhythmone%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%5BRX_UUID%5D")
cmpStrings(t, "adapters.rhythmone.usersync_url", cfg.Adapters[string(openrtb_ext.BidderRhythmone)].UserSyncURL, "https://sync.1rx.io/usersync2/rmphb?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redir=http%3A%2F%2Fprebid-server.prebid.org%2F%2Fsetuid%3Fbidder%3Drhythmone%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%5BRX_UUID%5D")
cmpBools(t, "account_required", cfg.AccountRequired, true)
cmpBools(t, "auto_gen_source_tid", cfg.AutoGenSourceTID, false)
cmpBools(t, "account_adapter_details", cfg.Metrics.Disabled.AccountAdapterDetails, true)
Expand Down
35 changes: 5 additions & 30 deletions endpoints/cookie_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,24 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"regexp"
"strconv"
"strings"

"github.com/PubMatic-OpenWrap/prebid-server/analytics"
"github.com/PubMatic-OpenWrap/prebid-server/config"
"github.com/PubMatic-OpenWrap/prebid-server/gdpr"
"github.com/PubMatic-OpenWrap/prebid-server/metrics"
"github.com/PubMatic-OpenWrap/prebid-server/openrtb_ext"
"github.com/PubMatic-OpenWrap/prebid-server/metrics"
"github.com/PubMatic-OpenWrap/prebid-server/privacy"
"github.com/PubMatic-OpenWrap/prebid-server/privacy/ccpa"
gdprPrivacy "github.com/PubMatic-OpenWrap/prebid-server/privacy/gdpr"
"github.com/PubMatic-OpenWrap/prebid-server/usersync"
"github.com/buger/jsonparser"
"github.com/golang/glog"
"github.com/julienschmidt/httprouter"
"io/ioutil"
"math/rand"
"net/http"
"strconv"
)

var secureFlagRegex = regexp.MustCompile(`(%7B|{)SecParam(%7D|})`)

func NewCookieSyncEndpoint(
syncers map[openrtb_ext.BidderName]usersync.Usersyncer,
cfg *config.Configuration,
Expand Down Expand Up @@ -161,14 +156,6 @@ func (deps *cookieSyncDeps) Endpoint(w http.ResponseWriter, r *http.Request, _ h
BidderStatus: make([]*usersync.CookieSyncBidders, 0, len(parsedReq.Bidders)),
}

//For secure = true flag on cookie
secParam := r.URL.Query().Get("sec")
refererHeader := r.Header.Get("Referer")
setSecureFlag := false
if secParam == "1" || strings.HasPrefix(refererHeader, "https") {
setSecureFlag = true
}

for i := 0; i < len(parsedReq.Bidders); i++ {
bidder := parsedReq.Bidders[i]

Expand All @@ -180,9 +167,6 @@ func (deps *cookieSyncDeps) Endpoint(w http.ResponseWriter, r *http.Request, _ h
}
syncInfo, err := deps.syncers[openrtb_ext.BidderName(newBidder)].GetUsersyncInfo(privacyPolicy)
if err == nil {

syncInfo.URL = setSecureParam(syncInfo.URL, setSecureFlag)

newSync := &usersync.CookieSyncBidders{
BidderCode: bidder,
NoCookie: true,
Expand Down Expand Up @@ -248,15 +232,6 @@ func cookieSyncStatus(syncCount int) string {
return "ok"
}

func setSecureParam(userSyncUrl string, isSecure bool) string {
var secParam = "0"
if isSecure {
secParam = "1"
}
syncURL := secureFlagRegex.ReplaceAllString(userSyncUrl, secParam)
return syncURL
}

type CookieSyncReq cookieSyncRequest
type CookieSyncResp cookieSyncResponse

Expand Down
Loading

0 comments on commit d7e2a8c

Please sign in to comment.