aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Session
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-06-11 10:45:19 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-06-14 08:09:36 +0200
commit8c47a632e0afc5b38093818f70dcf4cdead42b4d (patch)
treeb28f4dd055fae30ab2688f63ebe6eae00fa5f867 /lib/private/Session
parent479e31997f0ecde8d3cf59cc54c5f8ac4b1f80d8 (diff)
downloadnextcloud-server-8c47a632e0afc5b38093818f70dcf4cdead42b4d.tar.gz
nextcloud-server-8c47a632e0afc5b38093818f70dcf4cdead42b4d.zip
Allow updating the token on session regeneration
Sometimes when we force a session regeneration we want to update the current token for this session. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Session')
-rw-r--r--lib/private/Session/CryptoSessionData.php5
-rw-r--r--lib/private/Session/Internal.php33
-rw-r--r--lib/private/Session/Memory.php2
3 files changed, 36 insertions, 4 deletions
diff --git a/lib/private/Session/CryptoSessionData.php b/lib/private/Session/CryptoSessionData.php
index b63b568875e..01cac631870 100644
--- a/lib/private/Session/CryptoSessionData.php
+++ b/lib/private/Session/CryptoSessionData.php
@@ -150,10 +150,11 @@ class CryptoSessionData implements \ArrayAccess, ISession {
* Wrapper around session_regenerate_id
*
* @param bool $deleteOldSession Whether to delete the old associated session file or not.
+ * @param bool $updateToken Wheater to update the associated auth token
* @return void
*/
- public function regenerateId(bool $deleteOldSession = true) {
- $this->session->regenerateId($deleteOldSession);
+ public function regenerateId(bool $deleteOldSession = true, bool $updateToken = false) {
+ $this->session->regenerateId($deleteOldSession, $updateToken);
}
/**
diff --git a/lib/private/Session/Internal.php b/lib/private/Session/Internal.php
index 1d0466ec349..182754f457c 100644
--- a/lib/private/Session/Internal.php
+++ b/lib/private/Session/Internal.php
@@ -30,6 +30,10 @@ declare(strict_types=1);
namespace OC\Session;
+use OC\Authentication\Exceptions\InvalidTokenException;
+use OC\Authentication\Token\IProvider;
+use OC\SystemConfig;
+use OCP\IConfig;
use OCP\Session\Exceptions\SessionNotAvailableException;
/**
@@ -111,14 +115,41 @@ class Internal extends Session {
* Wrapper around session_regenerate_id
*
* @param bool $deleteOldSession Whether to delete the old associated session file or not.
+ * @param bool $updateToken Wheater to update the associated auth token
* @return void
*/
- public function regenerateId(bool $deleteOldSession = true) {
+ public function regenerateId(bool $deleteOldSession = true, bool $updateToken = false) {
+ $oldId = null;
+
+ if ($updateToken) {
+ // Get the old id to update the token
+ try {
+ $oldId = $this->getId();
+ } catch (SessionNotAvailableException $e) {
+ // We can't update a token if there is no previous id
+ $updateToken = false;
+ }
+ }
+
try {
@session_regenerate_id($deleteOldSession);
} catch (\Error $e) {
$this->trapError($e->getCode(), $e->getMessage());
}
+
+ if ($updateToken) {
+ // Get the new id to update the token
+ $newId = $this->getId();
+
+ /** @var IProvider $tokenProvider */
+ $tokenProvider = \OC::$server->query(IProvider::class);
+
+ try {
+ $tokenProvider->renewSessionToken($oldId, $newId);
+ } catch (InvalidTokenException $e) {
+ // Just ignore
+ }
+ }
}
/**
diff --git a/lib/private/Session/Memory.php b/lib/private/Session/Memory.php
index 79900bc8067..5a2a3039d7b 100644
--- a/lib/private/Session/Memory.php
+++ b/lib/private/Session/Memory.php
@@ -91,7 +91,7 @@ class Memory extends Session {
*
* @param bool $deleteOldSession
*/
- public function regenerateId(bool $deleteOldSession = true) {}
+ public function regenerateId(bool $deleteOldSession = true, bool $updateToken = false) {}
/**
* Wrapper around session_id