Skip to content

Commit

Permalink
Skip session validation during app load (Fixes nextcloud#20756)
Browse files Browse the repository at this point in the history
Adds parameter to User\Session:getUser() to skip validation, and
modifies OC_App::getEnabledApps() to use this parameter to skip
session validation when loading apps.

Signed-off-by: Scott Shambarger <devel@shambarger.net>
  • Loading branch information
sshambar committed Apr 30, 2020
1 parent b2b8be8 commit 581d300
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ public function setUser($user) {
/**
* get the current active user
*
* @param bool $validate whether to validate session
* @return IUser|null Current user, otherwise null
*/
public function getUser() {
public function getUser($validate = true) {
// FIXME: This is a quick'n dirty work-around for the incognito mode as
// described at https://github.com/owncloud/core/pull/12912#issuecomment-67391155
if (OC_User::isIncognitoMode()) {
Expand All @@ -236,11 +237,16 @@ public function getUser() {
if (is_null($uid)) {
return null;
}
$this->activeUser = $this->manager->get($uid);
if (is_null($this->activeUser)) {
// UserManager will cache user for later validation...
$user = $this->manager->get($uid);
if (is_null($user)) {
return null;
}
$this->validateSession();
if ($validate === true) {
// only set activeUser when validating...
$this->activeUser = $user;
$this->validateSession();
}
}
return $this->activeUser;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ public static function getEnabledApps(bool $forceRefresh = false, bool $all = fa
if ($all) {
$user = null;
} else {
$user = \OC::$server->getUserSession()->getUser();
// getUser but don't validate session yet
$user = \OC::$server->getUserSession()->getUser(false);
}

if (is_null($user)) {
Expand Down

0 comments on commit 581d300

Please sign in to comment.