Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Restrict /setuid for Prebid supported bidders only (prebid#1084)
Browse files Browse the repository at this point in the history
* Restrict /setuid for Prebid supported bidders only

* Improve some test cases based on code review comments
  • Loading branch information
mansinahar authored and guscarreon committed Oct 30, 2019
1 parent f817df7 commit 500f003
Show file tree
Hide file tree
Showing 2 changed files with 238 additions and 118 deletions.
19 changes: 16 additions & 3 deletions endpoints/setuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package endpoints

import (
"context"
"errors"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -55,9 +56,9 @@ func NewSetUIDEndpoint(cfg config.HostCookie, perms gdpr.Permissions, pbsanalyti
return
}

if bidder == "" {
if err := validateBidder(bidder); err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(`"bidder" query param is required`))
w.Write([]byte(err.Error()))
metrics.RecordUserIDSet(pbsmetrics.UserLabels{
Action: pbsmetrics.RequestActionErr,
Bidder: openrtb_ext.BidderName(bidder),
Expand All @@ -70,7 +71,7 @@ func NewSetUIDEndpoint(cfg config.HostCookie, perms gdpr.Permissions, pbsanalyti
uid := query.Get("uid")
so.UID = uid

var err error = nil
var err error
if uid == "" {
pc.Unsync(bidder)
} else {
Expand All @@ -91,6 +92,18 @@ func NewSetUIDEndpoint(cfg config.HostCookie, perms gdpr.Permissions, pbsanalyti
})
}

func validateBidder(bidderName string) error {
if bidderName == "" {
return errors.New(`"bidder" query param is required`)
}

// Fixes #1054
if _, ok := openrtb_ext.BidderMap[bidderName]; !ok {
return errors.New("The bidder name provided is not supported by Prebid Server")
}
return nil
}

// siteCookieCheck scans the input User Agent string to check if browser is Chrome and browser version is greater than the minimum version for adding the SameSite cookie attribute
func siteCookieCheck(ua string) bool {
result := false
Expand Down
Loading

0 comments on commit 500f003

Please sign in to comment.