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/Overlay
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/Overlay')
-rw-r--r--plugins/Overlay/API.php47
1 files changed, 0 insertions, 47 deletions
diff --git a/plugins/Overlay/API.php b/plugins/Overlay/API.php
index 22f11eba95..0d9ae9cdcb 100644
--- a/plugins/Overlay/API.php
+++ b/plugins/Overlay/API.php
@@ -9,11 +9,8 @@
namespace Piwik\Plugins\Overlay;
use Exception;
-use Piwik\Access;
use Piwik\Config;
-use Piwik\Container\StaticContainer;
use Piwik\DataTable;
-use Piwik\Piwik;
use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\Plugins\SitesManager\SitesManager;
use Piwik\Plugins\Transitions\API as APITransitions;
@@ -30,8 +27,6 @@ class API extends \Piwik\Plugin\API
*/
public function getTranslations($idSite)
{
- $this->authenticate($idSite);
-
$translations = array(
'oneClick' => 'Overlay_OneClick',
'clicks' => 'Overlay_Clicks',
@@ -48,8 +43,6 @@ class API extends \Piwik\Plugin\API
*/
public function getExcludedQueryParameters($idSite)
{
- $this->authenticate($idSite);
-
$sitesManager = APISitesManager::getInstance();
$site = $sitesManager->getSiteFromId($idSite);
@@ -71,8 +64,6 @@ class API extends \Piwik\Plugin\API
*/
public function getFollowingPages($url, $idSite, $period, $date, $segment = false)
{
- $this->authenticate($idSite);
-
$url = PageUrl::excludeQueryParametersFromUrl($url, $idSite);
// we don't unsanitize $url here. it will be done in the Transitions plugin.
@@ -100,42 +91,4 @@ class API extends \Piwik\Plugin\API
return $resultDataTable;
}
-
- /** Do cookie authentication. This way, the token can remain secret. */
- private function authenticate($idSite)
- {
- if (Piwik::isUserHasViewAccess($idSite)) {
- return; // user is already authenticated (e.g. API call with token_auth)
- }
-
- /**
- * Triggered immediately before the user is authenticated.
- *
- * This event can be used by plugins that provide their own authentication mechanism
- * to make that mechanism available. Subscribers should set the `'Piwik\Auth'` object in
- * the container to an object that implements the {@link Piwik\Auth} interface.
- *
- * **Example**
- *
- * use Piwik\Container\StaticContainer;
- *
- * public function initAuthenticationObject($activateCookieAuth)
- * {
- * StaticContainer::getContainer()->set('Piwik\Auth', new LDAPAuth($activateCookieAuth));
- * }
- *
- * @param bool $activateCookieAuth Whether authentication based on `$_COOKIE` values should
- * be allowed.
- */
- Piwik::postEvent('Request.initAuthenticationObject', array($activateCookieAuth = true));
-
- $auth = StaticContainer::get('Piwik\Auth');
- $success = Access::getInstance()->reloadAccess($auth);
-
- if (!$success) {
- throw new Exception('Authentication failed');
- }
-
- Piwik::checkUserHasViewAccess($idSite);
- }
}