mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix(profiler): Harden profiler writes
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
1f9f41a079
commit
a65207abd9
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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue