Skip to content

Commit d4df447

Browse files
add defense mechanism against failed or stalled cronjob
1 parent 37eb606 commit d4df447

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/collect-functions.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,18 @@ function determine_uniqueness_fingerprint(string $type, $thing): array
263263
$ip_address = get_client_ip();
264264
$visitor_id = \hash("xxh64", "{$seed_value}-{$user_agent}-{$ip_address}", false);
265265
$session_file = get_upload_dir() . "/sessions/{$visitor_id}";
266-
$things = \is_file($session_file) ? \file($session_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : [];
266+
$time_midnight = (new \DateTimeImmutable('today, midnight', get_site_timezone()))->getTimestamp();
267+
$things = [];
268+
269+
// only read file if it exists and is not from before today
270+
// this is to protect against a cronjob that didn't run on time
271+
if (\is_file($session_file)) {
272+
if (filemtime($session_file) < $time_midnight) {
273+
unlink($session_file);
274+
} else {
275+
$things = \file($session_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
276+
}
277+
}
267278

268279
// check if type indicator is in session file
269280
$unique_type = $type && ! \in_array($type[0], $things);

0 commit comments

Comments
 (0)