Skip to content

Commit 34b7b18

Browse files
Merge pull request #56031 from nextcloud/backport/55989/stable31
[stable31] fix(profiler): Harden profiler writes
2 parents 2c0d6d9 + b821573 commit 34b7b18

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/private/Profiler/FileProfilerStorage.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ public function find(?string $url, ?int $limit, ?string $method, ?int $start = n
4848
[$csvToken, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode] = $values;
4949
$csvTime = (int)$csvTime;
5050

51-
if ($url && !str_contains($csvUrl, $url) || $method && !str_contains($csvMethod, $method) || $statusCode && !str_contains($csvStatusCode, $statusCode)) {
51+
if (($url && !str_contains($csvUrl, $url))
52+
|| ($method && !str_contains($csvMethod, $method))
53+
|| ($statusCode && !str_contains($csvStatusCode, $statusCode))) {
5254
continue;
5355
}
5456

55-
if (!empty($start) && $csvTime < $start) {
57+
if ($start !== null && $csvTime < $start) {
5658
continue;
5759
}
5860

59-
if (!empty($end) && $csvTime > $end) {
61+
if ($end !== null && $csvTime > $end) {
6062
continue;
6163
}
6264

@@ -154,20 +156,27 @@ public function write(IProfile $profile): bool {
154156
return false;
155157
}
156158

157-
fputcsv($file, [
159+
fputcsv($file, array_map([$this, 'escapeFormulae'], [
158160
$profile->getToken(),
159161
$profile->getMethod(),
160162
$profile->getUrl(),
161163
$profile->getTime(),
162164
$profile->getParentToken(),
163165
$profile->getStatusCode(),
164-
]);
166+
]), escape: '');
165167
fclose($file);
166168
}
167169

168170
return true;
169171
}
170172

173+
protected function escapeFormulae(?string $value): ?string {
174+
if ($value !== null && preg_match('/^[=+\-@\t\r]/', $value)) {
175+
return "'" . $value;
176+
}
177+
return $value;
178+
}
179+
171180
/**
172181
* Gets filename to store data, associated to the token.
173182
*

0 commit comments

Comments
 (0)