-
Notifications
You must be signed in to change notification settings - Fork 845
ORTB Blocking Module: battr media type strictness #4551
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
base: master
Are you sure you want to change the base?
Conversation
…xistent types in imp; Added support video and audio battr
…dia-type-strictness-configuration-for-battr
| for i, imp := range payload.Request.Imp { | ||
| if values, ok := bTypeByImp[imp.ID]; ok && len(values) > 0 { | ||
| // Only apply if Banner exists | ||
| if imp.Banner != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to check again for banner object, as filterByMediaType already filters imps without banner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right.
I removed the redundant check.
| if values, ok := bAttrByImp[imp.ID]; ok && len(values) > 0 { | ||
| switch mediaType { | ||
| case "banner": | ||
| if imp.Banner != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove mediatype specific checks from here, as its already taken care by filterByMediaType or we can remove filterByMediaType function and keep these checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the redundant check.
| } | ||
| } | ||
| case "video": | ||
| if imp.Video != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as comment on line 509
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the redundant check.
| } | ||
| } | ||
| case "audio": | ||
| if imp.Audio != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as comment on line 509
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the redundant check.
…dia-type-strictness-configuration-for-battr
…unnecessary nil checks and improve code clarity; add tests for empty values and media type handling
Fix ORTB Blocking Module: Prevent Creation of Empty Media Type Objects
Issues: #4006, #3913
Problem Description
The ORTB blocking module was incorrectly adding
battr(blocked attributes) to media type objects (imp[].banner/video/audio.battr) even when the media type object didn't exist in the original request.The module would create empty
banner,video, oraudioobjects solely to injectbattrvalues, resulting in "bogus" media types in impressions that could confuse SSPs and lead to invalid bid requests.Example of Problematic Behavior
Before Fix:
{ "imp": [ { "id": "DLP_Desk_Top", "banner": { "format": [{"w": 728, "h": 90}], "battr": [1, 2, 3] } }, { "id": "imp-video-1", "banner": { "battr": [1, 2, 3] // Empty banner object created unnecessarily }, "video": { "mimes": ["video/mp4"], "minduration": 5, "maxduration": 30, "protocols": [2, 3], "w": 640, "h": 480 } } ] }Root Cause Analysis
Unconditional Object Creation: The
mutationForImpfunction was creating empty media type objects:Incorrect Existence Check: The attribute existence check was validating populated
BAttrarrays instead of checking if the media type object existed:Solution Implementation
1. Enhanced Configuration Support
Added comprehensive video and audio support to the configuration structure:
2. Media Type Validation
Implemented proper media type existence validation before applying
battr:3. Safe Media Type Filtering
Added utility function to ensure
battris only applied to existing media type objects:4. Type-Safe Mutation Creation
Implemented secure mutation functions that verify object existence before modification: