Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-06-11 11:45:19 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2018-07-09 17:27:12 +0300
commitf84789f88bee0b5a6f83f9729b99a299cc64665c (patch)
tree4cb0c463789379cd165b70130c93afb7d1cc348d /lib
parent57ca183ea42cab2b3c4b5ef2c0a5f058efc39ebe (diff)
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')
-rw-r--r--lib/private/Session/CryptoSessionData.php5
-rw-r--r--lib/private/Session/Internal.php33
-rw-r--r--lib/private/Session/Memory.php2
-rw-r--r--lib/private/User/Session.php2
-rw-r--r--lib/public/ISession.php5
5 files changed, 41 insertions, 6 deletions
diff --git a/lib/private/Session/CryptoSessionData.php b/lib/private/Session/CryptoSessionData.php
index 272e82ef496..24582b35186 100644
--- a/lib/private/Session/CryptoSessionData.php
+++ b/lib/private/Session/CryptoSessionData.php
@@ -149,10 +149,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($deleteOldSession = true) {
- $this->session->regenerateId($deleteOldSession);
+ public function regenerateId($deleteOldSession = true, $updateToken = false) {
+ $this->session->regenerateId($deleteOldSession, $updateToken);
}
/**
diff --git a/lib/private/Session/Internal.php b/lib/private/Session/Internal.php
index d137d72a048..20230acebe8 100644
--- a/lib/private/Session/Internal.php
+++ b/lib/private/Session/Internal.php
@@ -29,6 +29,10 @@
namespace OC\Session;
+use OC\Authentication\Exceptions\InvalidTokenException;
+use OC\Authentication\Token\IProvider;
+use OC\SystemConfig;
+use OCP\IConfig;
use OCP\Session\Exceptions\SessionNotAvailableException;
/**
@@ -110,14 +114,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($deleteOldSession = true) {
+ public function regenerateId($deleteOldSession = true, $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 22d6ffa0110..8975d8dfe0b 100644
--- a/lib/private/Session/Memory.php
+++ b/lib/private/Session/Memory.php
@@ -90,7 +90,7 @@ class Memory extends Session {
*
* @param bool $deleteOldSession
*/
- public function regenerateId($deleteOldSession = true) {}
+ public function regenerateId($deleteOldSession = true, $updateToken = false) {}
/**
* Wrapper around session_id
diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php
index 34319760c86..489f3cc0d3d 100644
--- a/lib/private/User/Session.php
+++ b/lib/private/User/Session.php
@@ -624,6 +624,8 @@ class Session implements IUserSession, Emitter {
try {
$sessionId = $this->session->getId();
$pwd = $this->getPassword($password);
+ // Make sure the current sessionId has no leftover tokens
+ $this->tokenProvider->invalidateToken($sessionId);
$this->tokenProvider->generateToken($sessionId, $uid, $loginName, $pwd, $name, IToken::TEMPORARY_TOKEN, $remember);
return true;
} catch (SessionNotAvailableException $ex) {
diff --git a/lib/public/ISession.php b/lib/public/ISession.php
index 2d234976862..36d855afbff 100644
--- a/lib/public/ISession.php
+++ b/lib/public/ISession.php
@@ -93,10 +93,11 @@ interface 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
- * @since 9.0.0
+ * @since 9.0.0, $updateToken added in 14.0.0
*/
- public function regenerateId($deleteOldSession = true);
+ public function regenerateId($deleteOldSession = true, $updateToken = false);
/**
* Wrapper around session_id