Skip to content

Commit bfa6608

Browse files
committed
chore(cypress): Try to analyze failures
Assisted-by: ClaudeCode:claude-fable-5 Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
1 parent 4da93ff commit bfa6608

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

core/Controller/CSRFTokenController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,19 @@ public function index(): JSONResponse {
6363
try {
6464
$session = \OCP\Server::get(\OCP\ISession::class);
6565
$raw = $this->request->getCookie(session_name());
66+
// Hash of the raw token value stored in this session. The matching
67+
// /login line logs the same storedTok; if they differ (or /login has
68+
// none) the two requests hit different sessions -> csrfCheckFailed.
69+
$storedTok = 'n/a';
70+
$t = $session->get('requesttoken');
71+
if (is_string($t) && $t !== '') {
72+
$storedTok = substr(md5($t), 0, 8);
73+
}
6674
\OCP\Server::get(\Psr\Log\LoggerInterface::class)->error(
6775
'[login-diag] CSRFTOKEN issued remote=' . $this->request->getRemoteAddress()
6876
. ' session=' . substr(md5((string)$session->getId()), 0, 8)
69-
. ' sessCookie=' . ($raw !== null ? substr(md5($raw), 0, 8) : 'none'),
77+
. ' sessCookie=' . ($raw !== null ? substr(md5($raw), 0, 8) : 'none')
78+
. ' storedTok=' . $storedTok,
7079
['app' => 'login-diag'],
7180
);
7281
} catch (\Throwable) {

core/Controller/LoginController.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,29 @@ private function logLoginDiag(string $what, string $user): void {
416416
} catch (\Throwable) {
417417
$sessCookie = 'err';
418418
}
419+
// Hash of the raw CSRF token value STORED in this session, and of the
420+
// value the client PROVIDED. If the /login session is the same one
421+
// /csrftoken issued into, storedTok here must equal the storedTok that
422+
// CSRFTOKEN logged. A mismatch proves the two requests hit different
423+
// sessions (or the token rotated) — the real csrfCheckFailed cause.
424+
$storedTok = 'n/a';
425+
try {
426+
$t = $this->session->get('requesttoken');
427+
if (is_string($t) && $t !== '') {
428+
$storedTok = substr(md5($t), 0, 8);
429+
}
430+
} catch (\Throwable) {
431+
$storedTok = 'err';
432+
}
433+
$providedTok = 'none';
434+
try {
435+
$p = $this->request->getParam('requesttoken');
436+
if (is_string($p) && $p !== '') {
437+
$providedTok = substr(md5($p), 0, 8);
438+
}
439+
} catch (\Throwable) {
440+
$providedTok = 'err';
441+
}
419442
\OCP\Server::get(\Psr\Log\LoggerInterface::class)->error(
420443
'[login-diag] ' . $what
421444
. ' user=' . $user
@@ -424,6 +447,8 @@ private function logLoginDiag(string $what, string $user): void {
424447
. ' sessCookie=' . $sessCookie
425448
. ' strictCookie=' . $strictCookie
426449
. ' sessHasReqToken=' . $sessHasReqToken
450+
. ' storedTok=' . $storedTok
451+
. ' providedTok=' . $providedTok
427452
. ' csrf=' . ($this->request->passesCSRFCheck() ? '1' : '0')
428453
. ' origin=' . $this->request->getHeader('Origin')
429454
. ' delay=' . $this->throttler->getDelay($remote, 'login'),

0 commit comments

Comments
 (0)