Merge pull request #56030 from nextcloud/backport/55989/stable32

[stable32] fix(profiler): Harden profiler writes
pull/55832/head
Joas Schilling 2025-10-27 17:03:08 +07:00 committed by GitHub
commit 06f6a1f177
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 5 deletions

@ -48,15 +48,17 @@ class FileProfilerStorage {
[$csvToken, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode] = $values;
$csvTime = (int)$csvTime;
if ($url && !str_contains($csvUrl, $url) || $method && !str_contains($csvMethod, $method) || $statusCode && !str_contains($csvStatusCode, $statusCode)) {
if (($url && !str_contains($csvUrl, $url))
|| ($method && !str_contains($csvMethod, $method))
|| ($statusCode && !str_contains($csvStatusCode, $statusCode))) {
continue;
}
if (!empty($start) && $csvTime < $start) {
if ($start !== null && $csvTime < $start) {
continue;
}
if (!empty($end) && $csvTime > $end) {
if ($end !== null && $csvTime > $end) {
continue;
}
@ -154,20 +156,27 @@ class FileProfilerStorage {
return false;
}
fputcsv($file, [
fputcsv($file, array_map([$this, 'escapeFormulae'], [
$profile->getToken(),
$profile->getMethod(),
$profile->getUrl(),
$profile->getTime(),
$profile->getParentToken(),
$profile->getStatusCode(),
], escape: '');
]), escape: '');
fclose($file);
}
return true;
}
protected function escapeFormulae(?string $value): ?string {
if ($value !== null && preg_match('/^[=+\-@\t\r]/', $value)) {
return "'" . $value;
}
return $value;
}
/**
* Gets filename to store data, associated to the token.
*