Skip to content

[sc-19529] Add TCF 2.3 support#48

Open
osazos wants to merge 3 commits intoprebid:masterfrom
onfocusio:feature/tcf-2.3
Open

[sc-19529] Add TCF 2.3 support#48
osazos wants to merge 3 commits intoprebid:masterfrom
onfocusio:feature/tcf-2.3

Conversation

@osazos
Copy link

@osazos osazos commented Feb 5, 2026

This PR implements support for the TCF 2.3 Disclosed Vendors segment (#46), which becomes mandatory on March 1st, 2025. Given the short timeline for compliance, I extended the existing ConsentMetadata structure to parse and store disclosed vendors data, reusing the established parseBitField() and parseRangeSection() patterns. The implementation fully supports both BitField and RangeSection encoding modes as specified in the TCF 2.3 standard. While this approach delivers quickly and maintains backward compatibility, future refactoring should separate segment parsing concerns for better modularity.

Changes

  • API Extension: Added VendorDisclosed(id), VendorDisclosedMaxVendorId(), and HasDisclosedVendors() methods to the VendorConsents interface
  • Segment Parsing: Created disclosed_vendors.go to parse the Disclosed Vendors segment (segment type 1) with full support for both BitField (IsRangeEncoding=0) and RangeSection (IsRangeEncoding=1) encoding modes
  • Core String Parsing: Modified parseWithDisclosedVendors() to iterate through consent string segments and detect the disclosed vendors segment by type
  • Metadata Storage: Extended ConsentMetadata struct with disclosedVendors and hasDisclosedVendors fields
  • Backward Compatibility: TCF 2.0/2.2 consent strings without disclosed vendors segment continue to work correctly (VendorDisclosed() returns false)
  • Range Section Fix: Updated parseRangeSection() to calculate minimum required bytes dynamically instead of using a hardcoded 31-byte check, enabling proper segment parsing

Testing

  • Comprehensive test coverage in disclosed_vendors_test.go for BitField encoding
  • Tests validate segment type detection, max vendor ID parsing, and consent queries
  • Multiple segments can appear in any order (tested in TestSegmentsInAnyOrder)
  • Backward compatibility tests ensure legacy consent strings behave correctly
  • RangeSection encoding is fully implemented and code paths are tested through existing TCF 2.0 core string tests

Technical Details

Segments after the core string can appear in any order, so the parser checks each segment's type before processing. The implementation correctly handles both encoding modes by checking bit 19 and delegating to either parseBitField() or parseRangeSection() accordingly.

Future Considerations

The current implementation tightly couples segment parsing within ConsentMetadata. As the TCF spec evolves and additional segments are needed (e.g., Publisher TC), consider refactoring to a cleaner segment-based architecture where each segment type has its own parser and data structure.

@Katarzyna-B
Copy link

@osazos Do you know when we plan to release these changes?

@osazos osazos force-pushed the feature/tcf-2.3 branch 2 times, most recently from bc7921f to f3fe261 Compare February 12, 2026 13:50
DisclosedVendors segment parsing
@arachman
Copy link

@hhhjort can you help with this?

@bsardo
Copy link
Contributor

bsardo commented Feb 25, 2026

@arachman is this meant to work in conjunction with #49?

@osazos
Copy link
Author

osazos commented Feb 25, 2026

@arachman is this meant to work in conjunction with #49?

Hi @bsardo both MR's are independents. For what it's worth, this one has been created 1st and has been reviewed by @Katarzyna-B.

api/consent.go Outdated
// this returns false to maintain backward compatibility.
VendorDisclosed(id uint16) bool

VendorDisclosedMaxVendorId() uint16

Choose a reason for hiding this comment

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

s/VendorDisclosedMaxVendorId/VendorDisclosedMaxVendorID

@osazos osazos force-pushed the feature/tcf-2.3 branch from f3fe261 to f81eef3 Compare March 4, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants