Skip to content

Commit

Permalink
limit string length on data ingestion, see https://3v4l.org/Y69ZN
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Nov 21, 2024
1 parent 64b9b8f commit f562c4f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ function extract_pageview_data(array $raw): array
return [];
}

// limit referrer URL to 255 chars
$referrer_url = \substr($referrer_url, 0, 255);

return [
'p', // type indicator
$post_id,
Expand All @@ -63,10 +66,14 @@ function extract_event_data(array $raw): array
$event_name = \trim($raw['e']);
$event_param = \trim($raw['p']);

if (strlen($event_name) === 0) {
if (\strlen($event_name) === 0) {
return [];
}

// limit event name and parameter lengths
$event_name = \substr($event_name, 0, 100);
$event_param = \substr($event_param, 0, 185);

return [
'e', // type indicator
$event_name, // 0: event name
Expand Down Expand Up @@ -117,7 +124,7 @@ function collect_request()
$posts_viewed[] = (int) $_GET['p'];
}
$cookie = \join(',', $posts_viewed);
\setcookie('_koko_analytics_pages_viewed', $cookie, time() + 6 * 3600, '/');
\setcookie('_koko_analytics_pages_viewed', $cookie, \time() + 6 * 3600, '/');
}

exit;
Expand Down

0 comments on commit f562c4f

Please sign in to comment.