diff --git a/src/applications/auth/engine/PhabricatorAuthSessionEngine.php b/src/applications/auth/engine/PhabricatorAuthSessionEngine.php index 53de32376b..718f48c42c 100644 --- a/src/applications/auth/engine/PhabricatorAuthSessionEngine.php +++ b/src/applications/auth/engine/PhabricatorAuthSessionEngine.php @@ -165,6 +165,9 @@ final class PhabricatorAuthSessionEngine extends Phobject { // TTL back up to the full duration. The idea here is that sessions are // good forever if used regularly, but get GC'd when they fall out of use. + // NOTE: If we begin rotating session keys when extending sessions, the + // CSRF code needs to be updated so CSRF tokens survive session rotation. + if (time() + (0.80 * $ttl) > $session->getSessionExpires()) { $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $conn_w = $session_table->establishConnection('w'); diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index bbdc9dbdfe..5a0d7e47f1 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -339,6 +339,10 @@ final class PhabricatorUser $vec = $this->getAlternateCSRFString(); } + if ($this->hasSession()) { + $vec = $vec.$this->getSession()->getSessionKey(); + } + $time_block = floor($epoch / $frequency); $vec = $vec.$key.$time_block;