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

Add an app.id blacklist to PBS and reject requests from it #969

Merged
merged 19 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ type Configuration struct {
DefReqConfig DefReqConfig `mapstructure:"default_request"`

VideoStoredRequestRequired bool `mapstructure:"video_stored_request_required"`

// PBS-418 array of blacklisted apps and its correpondent hash table to be instantly accessed.
BlacklistedApps []string `mapstructure:"blacklisted_apps,flow"`
BlacklistedAppMap map[string]bool
}

type HTTPClient struct {
Expand Down Expand Up @@ -393,6 +397,13 @@ func New(v *viper.Viper) (*Configuration, error) {
for i := 0; i < len(c.GDPR.NonStandardPublishers); i++ {
c.GDPR.NonStandardPublisherMap[c.GDPR.NonStandardPublishers[i]] = 1
}

// To look for a request's app_id in O(1) time, we fill this hash table located in the
// the BlacklistedApps field of the Configuration struct defined in this file
c.BlacklistedAppMap = make(map[string]bool)
for i := 0; i < len(c.BlacklistedApps); i++ {
c.BlacklistedAppMap[c.BlacklistedApps[i]] = true
}
return &c, nil
}

Expand Down
10 changes: 10 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ adapters:
endpoint: http://test-bid.ybp.yahoo.com/bid/appnexuspbs
adkerneladn:
usersync_url: https://tag.adkernel.com/syncr?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&r=
blacklisted_apps: ["spamAppID","sketchy-app-id"]
`)

var invalidAdapterEndpointConfig = []byte(`
Expand Down Expand Up @@ -176,6 +177,15 @@ func TestFullConfig(t *testing.T) {
_, found = cfg.GDPR.NonStandardPublisherMap["appnexus"]
cmpBools(t, "cfg.GDPR.NonStandardPublisherMap", found, false)

//Assert the NonStandardPublishers was correctly unmarshalled
cmpStrings(t, "blacklisted_apps", cfg.BlacklistedApps[0], "spamAppID")
cmpStrings(t, "blacklisted_apps", cfg.BlacklistedApps[1], "sketchy-app-id")

//Assert the BlacklistedAppMap hash table was built correctly
for i := 0; i < len(cfg.BlacklistedApps); i++ {
cmpBools(t, "cfg.BlacklistedAppMap", cfg.BlacklistedAppMap[cfg.BlacklistedApps[i]], true)
}

cmpStrings(t, "currency_converter.fetch_url", cfg.CurrencyConverter.FetchURL, "https://currency.prebid.org")
cmpInts(t, "currency_converter.fetch_interval_seconds", cfg.CurrencyConverter.FetchIntervalSeconds, 1800)
cmpStrings(t, "recaptcha_secret", cfg.RecaptchaSecret, "asdfasdfasdfasdf")
Expand Down
3 changes: 3 additions & 0 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http
labels.Source = pbsmetrics.DemandApp
labels.RType = pbsmetrics.ReqTypeORTB2App
labels.PubID = effectivePubID(req.App.Publisher)
if _, found := deps.cfg.BlacklistedAppMap[labels.PubID]; found {
return
guscarreon marked this conversation as resolved.
Show resolved Hide resolved
}
} else { //req.Site != nil
labels.Source = pbsmetrics.DemandWeb
if usersyncs.LiveSyncCount() == 0 {
Expand Down
3 changes: 3 additions & 0 deletions endpoints/openrtb2/video_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ func (deps *endpointDeps) VideoAuctionEndpoint(w http.ResponseWriter, r *http.Re
if bidReq.App != nil {
labels.Source = pbsmetrics.DemandApp
labels.PubID = effectivePubID(bidReq.App.Publisher)
if _, found := deps.cfg.BlacklistedAppMap[labels.PubID]; found {
return
guscarreon marked this conversation as resolved.
Show resolved Hide resolved
}
} else { // both bidReq.App == nil and bidReq.Site != nil are true
labels.Source = pbsmetrics.DemandWeb
if usersyncs.LiveSyncCount() == 0 {
Expand Down