From 34f3ec00880806bc71d60a684259aa3aca918baf Mon Sep 17 00:00:00 2001 From: Tiago Peczenyj Date: Fri, 15 Dec 2023 16:37:20 +0100 Subject: [PATCH] force read the first segment as core string --- lib/GDPR/IAB/TCFv2.pm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/GDPR/IAB/TCFv2.pm b/lib/GDPR/IAB/TCFv2.pm index 5bc30dc..a7ec52c 100644 --- a/lib/GDPR/IAB/TCFv2.pm +++ b/lib/GDPR/IAB/TCFv2.pm @@ -434,7 +434,15 @@ sub TO_JSON { sub _decode_tc_string_segments { my $tc_string = shift; - my (@parts) = split CONSENT_STRING_TCF_V2->{SEPARATOR}, $tc_string; + my ( $core, @parts ) = split CONSENT_STRING_TCF_V2->{SEPARATOR}, + $tc_string; + + my $core_data = _validate_and_decode_base64($core); + my $core_data_size = length($core_data) / 8; + + croak + "vendor consent strings are at least @{[ CONSENT_STRING_TCF_V2->{MIN_BYTE_SIZE} ]} bytes long (got ${core_data_size} bytes)" + if $core_data_size < CONSENT_STRING_TCF_V2->{MIN_BYTE_SIZE}; my %segments; @@ -446,19 +454,9 @@ sub _decode_tc_string_segments { $segments{$segment_type} = $decoded; } - croak "missing core section" - unless exists $segments{ SEGMENT_TYPES->{CORE} }; - - my $core_data = $segments{ SEGMENT_TYPES->{CORE} }; my $disclosed_vendors = $segments{ SEGMENT_TYPES->{DISCLOSED_VENDORS} }; my $publisher_tc = $segments{ SEGMENT_TYPES->{PUBLISHER_TC} }; - my $core_data_size = length($core_data) / 8; - - croak - "vendor consent strings are at least @{[ CONSENT_STRING_TCF_V2->{MIN_BYTE_SIZE} ]} bytes long (got ${core_data_size} bytes)" - if $core_data_size < CONSENT_STRING_TCF_V2->{MIN_BYTE_SIZE}; - # return hashref return { core_data => $core_data,