Skip to content

UOE-6121: Reverting changes for sec parameter #123

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

Merged
merged 8 commits into from
Feb 25, 2021
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
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
36 changes: 1 addition & 35 deletions adapters/pubmatic/pubmatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/magiconair/properties/assert"
"io/ioutil"
"math/rand"
"net/http"
Expand Down Expand Up @@ -668,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 Expand Up @@ -799,36 +798,3 @@ func TestCopySBExtToBidExtWithNoSeatExt(t *testing.T) {
t.Errorf("it should not be nil")
}
}

func TestMakeRequestsTrimsPubID(t *testing.T) {
var a PubmaticAdapter
a.URI = "http://test.com/openrtb2"

var bidderExt adapters.ExtImpBidder
extImpPubMatic := openrtb_ext.ExtImpPubmatic{}
extImpPubMatic.PublisherId = " 5890 "
bidderExt.Bidder, _ = json.Marshal(extImpPubMatic)
extRaw, _ := json.Marshal(bidderExt)

var w, h uint64
w = 300
h = 250
var impression = openrtb.Imp{
Banner: &openrtb.Banner{
W: &w,
H: &h,
},
Ext: extRaw,
}
request := &openrtb.BidRequest{
Imp: []openrtb.Imp{impression},
Site: &openrtb.Site{
Publisher: &openrtb.Publisher{},
},
}
a.MakeRequests(request, nil)

updatedPubID := request.Site.Publisher.ID

assert.Equal(t, updatedPubID, "5890", "Publisher.ID field should be trimmed")
}
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
140 changes: 69 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
41 changes: 5 additions & 36 deletions endpoints/cookie_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ 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"
Expand All @@ -24,18 +17,14 @@ import (
"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,
syncPermissions gdpr.Permissions,
metrics metrics.MetricsEngine,
pbsAnalytics analytics.PBSAnalyticsModule,
func NewCookieSyncEndpoint(syncers map[openrtb_ext.BidderName]usersync.Usersyncer, cfg *config.Configuration, syncPermissions gdpr.Permissions, metrics metrics.MetricsEngine, pbsAnalytics analytics.PBSAnalyticsModule,
bidderMap map[string]openrtb_ext.BidderName) httprouter.Handle {

bidderLookup := make(map[string]struct{})
for k := range bidderMap {
bidderLookup[k] = struct{}{}
Expand Down Expand Up @@ -161,14 +150,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 +161,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 +226,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