Skip to content

Commit 736a5f9

Browse files
fix(session): Log critical conditions where sessions might be lost
* Regenerating session when cookies can't be sent -> lost * Regenerating session ID and deleting old data -> possible loss Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent 3062ceb commit 736a5f9

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

lib/private/Session/Internal.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
use OC\Authentication\Token\IProvider;
3838
use OCP\Session\Exceptions\SessionNotAvailableException;
3939
use Psr\Log\LoggerInterface;
40+
use function headers_sent;
41+
use function OCP\Log\logger;
4042

4143
/**
4244
* Class Internal
@@ -142,6 +144,14 @@ public function regenerateId(bool $deleteOldSession = true, bool $updateToken =
142144
}
143145
}
144146

147+
if (headers_sent()) {
148+
logger('core')->critical('Regenerating session ID but headers have been sent. This session will be lost.', [
149+
'deleteOldSession' => $deleteOldSession,
150+
]);
151+
} else if ($deleteOldSession) {
152+
logger('core')->warning('Calling session_regenerate_id with delete_old_session=true can lead to lost sessions');
153+
}
154+
145155
try {
146156
@session_regenerate_id($deleteOldSession);
147157
} catch (\Error $e) {
@@ -226,6 +236,12 @@ private function startSession(bool $silence = false, bool $readAndClose = true)
226236
if (\OC::hasSessionRelaxedExpiry()) {
227237
$sessionParams['read_and_close'] = $readAndClose;
228238
}
239+
if (headers_sent()) {
240+
logger('core')->critical('Starting session but headers have been sent. This session will be lost.', [
241+
'silence' => $silence,
242+
'readAndClos' => $readAndClose,
243+
]);
244+
}
229245
$this->invoke('session_start', [$sessionParams], $silence);
230246
}
231247
}

0 commit comments

Comments
 (0)