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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <diosmosis@users.noreply.github.com>2018-07-27 00:24:52 +0300
committerGitHub <noreply@github.com>2018-07-27 00:24:52 +0300
commit35bd641d69235420f69da986d77437af700a6164 (patch)
treeb83792eba151782f3a4776217e1c96d511577719 /plugins/Login/Controller.php
parentc5b46d7e61bd169b169470f8df9247e6f6781cc0 (diff)
Sessions with more security (#12208)
* Modifying "cookie authentication" to be more secure. Instead of authenticating by token auth if it exists in the cookie, validate an existing session. If the session has the user name stored as a session var, it has been authenticated. If the request has the same IP address and user agent as the request that created the session, the request is from the user that created the session. If both of these are true, then the session is valid, and we don't need a token auth to authenticate. If the session is deleted before the Piwik auth cookie expires (due to garbage collection), we attempt to re-authenticate using a secure hash of the token auth. We don't do this on every request since password_verify() will, at BEST, add 3.5ms to every request. * Invalidate existing sessions after user password change. Invalidation is accomplished w/o having to individually touch sessions by: 1. Using the password hash as the piwik_auth key secret, instead of the token auth. So when a password changes, existing piwik_auth keys are no longer valid. This affects session re-authentication. 2. Saving the session start time & the last time a user's password was modified, and checking that the session start time is always newer than the password modification time. * Set session.gc_maxlifetime to login_cookie_expire time so session data does not disappear, remove session re-auth functionality & tie cookie hash to password modified time instead of password hash to retain automatic session invalidation on password change. * In SessionInitializer, clear other cookie values so previously stored token auths will be removed. * Make sure anonymous user is still default user whan authenticating. * fixing test failures * Remove hash checking in piwik_auth cookie. piwik_auth cookie still required since it's presence indicates we should use SessionAuth instead of the normal authentication mechanism. Since there's always a session, even if you're not logged in, PIWIK_SESSID can't be used by itself to determine this. * Make sure session auth doesnt break in edge case where ts_password_modified column does not exist. * Clarify session destruction/invalidation logic in SessionAuth. * Make UsersManagerTest slightly more comprehensive. * Use Date::now()->getTimestampUTC() instead of time() in SessionFingerprint::initialize(). * Check getUser returns correct user info in SessionAuth for sanity. * Add SessionInitializer::getAuthCookie() back since it is @api. * Remove IP address from session auth info + check. * Refactor session start changes so it is started in one place only. * Remove SessionAuthCookieFactory & deprecate auth cookie INI config vars (still needed for SessionInitializer deprectaed method). * Make sure user can still login if ts_password_modified column is not present in database. * Rename ts_password_modified Update class. * Update comment in SessionAuth to include why Piwik tries to create another session. * Restore 3.x-dev SessionInitializer for BC (deprecated), move new SessionInitializer to core, add tests for both SessionInitializers. * Change update to 3.5 version. * Make sure normal auth implementation is used if sessionauth fails so anonymous user can be logged in. * On logout clear session fingerprint so same session cannot be used to login. * Change update name + bump version, and make sure Session::rememberMe() is called before session is started (otherwise it has no effect). * Fixing tests. * apply review fixes * remove test
Diffstat (limited to 'plugins/Login/Controller.php')
-rw-r--r--plugins/Login/Controller.php20
1 files changed, 8 insertions, 12 deletions
diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php
index c933214b01..3e7eac57a6 100644
--- a/plugins/Login/Controller.php
+++ b/plugins/Login/Controller.php
@@ -39,7 +39,7 @@ class Controller extends \Piwik\Plugin\Controller
protected $auth;
/**
- * @var SessionInitializer
+ * @var \Piwik\Session\SessionInitializer
*/
protected $sessionInitializer;
@@ -65,7 +65,7 @@ class Controller extends \Piwik\Plugin\Controller
$this->auth = $auth;
if (empty($sessionInitializer)) {
- $sessionInitializer = new SessionInitializer();
+ $sessionInitializer = new \Piwik\Session\SessionInitializer();
}
$this->sessionInitializer = $sessionInitializer;
}
@@ -100,9 +100,8 @@ class Controller extends \Piwik\Plugin\Controller
$login = $this->getLoginFromLoginOrEmail($loginOrEmail);
$password = $form->getSubmitValue('form_password');
- $rememberMe = $form->getSubmitValue('form_rememberme') == '1';
try {
- $this->authenticateAndRedirect($login, $password, $rememberMe);
+ $this->authenticateAndRedirect($login, $password);
} catch (Exception $e) {
$messageNoAccess = $e->getMessage();
}
@@ -173,7 +172,7 @@ class Controller extends \Piwik\Plugin\Controller
$urlToRedirect = Common::getRequestVar('url', $currentUrl, 'string');
$urlToRedirect = Common::unsanitizeInputValue($urlToRedirect);
- $this->authenticateAndRedirect($login, $password, false, $urlToRedirect, $passwordHashed = true);
+ $this->authenticateAndRedirect($login, $password, $urlToRedirect, $passwordHashed = true);
}
/**
@@ -201,12 +200,11 @@ class Controller extends \Piwik\Plugin\Controller
*
* @param string $login user name
* @param string $password plain-text or hashed password
- * @param bool $rememberMe Remember me?
* @param string $urlToRedirect URL to redirect to, if successfully authenticated
* @param bool $passwordHashed indicates if $password is hashed
* @return string failure message if unable to authenticate
*/
- protected function authenticateAndRedirect($login, $password, $rememberMe, $urlToRedirect = false, $passwordHashed = false)
+ protected function authenticateAndRedirect($login, $password, $urlToRedirect = false, $passwordHashed = false)
{
Nonce::discardNonce('Login.login');
@@ -217,7 +215,7 @@ class Controller extends \Piwik\Plugin\Controller
$this->auth->setPasswordHash($password);
}
- $this->sessionInitializer->initSession($this->auth, $rememberMe);
+ $this->sessionInitializer->initSession($this->auth);
// remove password reset entry if it exists
$this->passwordResetter->removePasswordResetInfo($login);
@@ -357,14 +355,12 @@ class Controller extends \Piwik\Plugin\Controller
/**
* Clear session information
*
- * @param none
* @return void
*/
public static function clearSession()
{
- $authCookieName = Config::getInstance()->General['login_cookie_name'];
- $cookie = new Cookie($authCookieName);
- $cookie->delete();
+ $sessionFingerprint = new Session\SessionFingerprint();
+ $sessionFingerprint->clear();
Session::expireSessionCookie();
}