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

Added header User Agent decoding #1268

Merged
merged 4 commits into from
Apr 22, 2020
Merged
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions endpoints/openrtb2/video_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"strings"
"time"

"github.com/buger/jsonparser"
jsonpatch "github.com/evanphx/json-patch"
"github.com/evanphx/json-patch"
"github.com/gofrs/uuid"
"github.com/prebid/prebid-server/errortypes"

Expand Down Expand Up @@ -617,7 +618,9 @@ func (deps *endpointDeps) parseVideoRequest(request []byte, headers http.Header)

//if Device.UA is not present in request body, init it with user-agent from request header if it's present
if req.Device.UA == "" {
req.Device.UA = headers.Get("User-Agent")
ua := headers.Get("User-Agent")
ua, _ = url.QueryUnescape(ua)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change which affects everyone. How will this behave when the user agent is not url encoded? Also, please never ignore errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi we tested with a value that's not encoded and QueryUnescape() returns the same value in that case. In the unlikely event that an unencoded value contains a decodable character sequence the return wouldn't match, but that's probably a pretty extreme edge case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at samples of UA strings, the '+' character may sometimes appear and the '%' character really doesn't. The + character would get changed to a space if not actually encoded. Perhaps you can check for the presence of a '%' as a best guess if the UA is encoded? Whatever you think is the best choice for this usecase. Please document your decision / explanation in a code block and also in the docs. This is one of those small hidden things which may infuriate someone down the road trying to debug.

GoLang already checks for invalid escape sequences and errors out, which now causes you to fallback to the original string.. which is good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Check added.
I also added a comment in code. Do you want me to mention it in prebid.org docs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is good for this PR. Thank you. I would like it to be mention in prebid.org docs as well, but I see that as a follow-up and not a blocker.

req.Device.UA = ua
}

errL, podErrors := deps.validateVideoRequest(req)
Expand Down