Skip to content
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
5 changes: 5 additions & 0 deletions config/requestvalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ type RequestValidation struct {

IPv6PrivateNetworks []string `mapstructure:"ipv6_private_networks,flow"`
IPv6PrivateNetworksParsed []net.IPNet

// LogBadInputRequestBody enables logging of raw request body for badinput errors.
// When enabled, the raw HTTP request body will be logged even if it's not valid JSON.
// Default is false (disabled).
LogBadInputRequestBody bool `mapstructure:"log_badinput_request_body"`
}

// Parse converts the CIDR representation of the IPv4 and IPv6 private networks as net.IPNet structs, or returns an error if at least one is invalid.
Expand Down
14 changes: 10 additions & 4 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http

req, impExtInfoMap, storedAuctionResponses, storedBidResponses, bidderImpReplaceImp, account, rawRequestBody, errL := deps.parseRequest(r, &labels, hookExecutor)
if errortypes.ContainsFatalError(errL) {
logBadInputRequest(errL, req, rawRequestBody)
logBadInputRequest(errL, req, rawRequestBody, deps.cfg.RequestValidation.LogBadInputRequestBody)
if writeError(errL, w, &labels) {
return
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http
err := deps.setIntegrationType(req, account)
if err != nil {
errL = append(errL, err)
logBadInputRequest(errL, req, rawRequestBody)
logBadInputRequest(errL, req, rawRequestBody, deps.cfg.RequestValidation.LogBadInputRequestBody)
writeError(errL, w, &labels)
return
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http
rejectErr, isRejectErr := hookexecution.CastRejectErr(err)
if err != nil && !isRejectErr {
if errortypes.ReadCode(err) == errortypes.BadInputErrorCode {
logBadInputRequest([]error{err}, req, rawRequestBody)
logBadInputRequest([]error{err}, req, rawRequestBody, deps.cfg.RequestValidation.LogBadInputRequestBody)
writeError([]error{err}, w, &labels)
return
}
Expand Down Expand Up @@ -1938,7 +1938,7 @@ func setDoNotTrackImplicitly(httpReq *http.Request, r *openrtb_ext.RequestWrappe
}

// logBadInputRequest logs the request and errors for badinput cases
func logBadInputRequest(errs []error, req *openrtb_ext.RequestWrapper, rawRequestBody []byte) {
func logBadInputRequest(errs []error, req *openrtb_ext.RequestWrapper, rawRequestBody []byte, logRequestBody bool) {
// Check if this is a badinput case (not BlockedApp, AccountDisabled, or MalformedAcct)
isBadInput := true
for _, err := range errs {
Expand All @@ -1953,6 +1953,12 @@ func logBadInputRequest(errs []error, req *openrtb_ext.RequestWrapper, rawReques
return
}

// Only log request body if the feature is enabled
if !logRequestBody {
logger.Errorf("/openrtb2/auction BadInput errors: %v", errs)
return
}

// Log the request and errors for badinput
// Prefer raw request body if available (even if it's not valid JSON)
if len(rawRequestBody) > 0 {
Expand Down