Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions db_structure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,36 @@

</table>

<table>
<!--
Stores the used sessions to reduce the risks of session collisions
-->
<name>*dbprefix*sessions</name>
<declaration>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LukasReschke should we add a user column to allow session enum on user basis?

I'm thinking about the scenario of password-change where we want to invalidate all user sessions ....

(there was an issue once by @danimo ....)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. We can indeed implement this with this approach. – I will think about an actual implementation and merge it into this PR.

Todo:

  1. Add user id to database
  2. Read action needs to check if session is terminated, if yes: invalidate the session

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. This is rather hard to do since we have a circular dependency, in order to read the user we need to read the session which is not going to work here. There are ways to work around this by moving this code to another place but this requires quite some more changes than the integration we have right now.

I'll think about it…

<field>
<name>hashed_id</name>
<type>string</type>
<length>128</length>
</field>
<field>
<name>last_used</name>
<type>integer</type>
<default></default>
<notnull>false</notnull>
</field>

<index>
<primary>true</primary>
<unique>true</unique>
<name>hashed_id_index</name>
<field>
<name>hashed_id</name>
<sorting>ascending</sorting>
</field>
</index>
</declaration>
</table>

<table>

<!--
Expand Down
26 changes: 23 additions & 3 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,29 @@ public static function initTemplateEngine() {
}

public static function initSession() {
// Try to set the session lifetime
$sessionLifeTime = self::getSessionLifeTime();
@ini_set('session.gc_maxlifetime', (int)$sessionLifeTime);

/**
* Use a custom session handler to store the data encrypted within the
* session this is only possible after the instance has been installed
* and since this may also happen after an update case we need to verify
* the version as well.
*/
if(self::$server->getConfig()->getSystemValue('installed', false)
&& version_compare(self::$server->getConfig()->getSystemValue('version', 0), '8.2.0.2', 'gt')) {
$handler = new \OC\Session\CryptoSessionHandler(
self::$server->getCrypto(),
self::$server->getSecureRandom(),
self::$server->getDatabaseConnection(),
self::$server->getConfig(),
self::$server->getTimeFactory(),
self::$server->getLogger()
);
session_set_save_handler($handler, true);
}

// prevents javascript from accessing php session cookies
ini_set('session.cookie_httponly', true);

Expand Down Expand Up @@ -634,9 +657,6 @@ public static function init() {
\OC::$server->getConfig()->deleteAppValue('core', 'cronErrors');
}
}
//try to set the session lifetime
$sessionLifeTime = self::getSessionLifeTime();
@ini_set('gc_maxlifetime', (string)$sessionLifeTime);

$systemConfig = \OC::$server->getSystemConfig();

Expand Down
16 changes: 15 additions & 1 deletion lib/private/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OC\AppFramework\Http\Request;
use OC\AppFramework\Db\Db;
use OC\AppFramework\Utility\SimpleContainer;
use OC\AppFramework\Utility\TimeFactory;
use OC\Command\AsyncBus;
use OC\Diagnostics\EventLogger;
use OC\Diagnostics\NullEventLogger;
Expand Down Expand Up @@ -157,7 +158,10 @@ public function __construct($webRoot) {
});
$this->registerService('UserSession', function (Server $c) {
$manager = $c->getUserManager();
$userSession = new \OC\User\Session($manager, new \OC\Session\Memory(''));

$session = new \OC\Session\Memory('');

$userSession = new \OC\User\Session($manager, $session);
$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
});
Expand Down Expand Up @@ -358,6 +362,9 @@ public function __construct($webRoot) {
$c->getL10N('lib', $language)
);
});
$this->registerService('TimeFactory', function() {
return new TimeFactory();
});
$this->registerService('MountConfigManager', function () {
$loader = \OC\Files\Filesystem::getLoader();
return new \OC\Files\Config\MountProviderCollection($loader);
Expand Down Expand Up @@ -611,6 +618,13 @@ public function getConfig() {
return $this->query('AllConfig');
}

/**
* @return \OCP\AppFramework\Utility\ITimeFactory
*/
public function getTimeFactory() {
return $this->query('TimeFactory');
}

/**
* For internal use only
*
Expand Down
Loading