Skip to content

Commit 9d1e4e0

Browse files
author
Albert Santoni
committed
Session pinning fix
1 parent 653f0e0 commit 9d1e4e0

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

airtime_mvc/application/Bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
require_once "OsPath.php";
1515
require_once "Database.php";
1616
require_once "Timezone.php";
17+
require_once "Auth.php";
1718
require_once __DIR__.'/forms/helpers/ValidationTypes.php';
1819
require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
20+
1921

2022
require_once (APPLICATION_PATH."/logging/Logging.php");
2123
Logging::setLogPath('/var/log/airtime/zendphp.log');
@@ -25,6 +27,8 @@
2527

2628
Zend_Validate::setDefaultNamespaces("Zend");
2729

30+
Application_Model_Auth::pinSessionToClient(Zend_Auth::getInstance());
31+
2832
$front = Zend_Controller_Front::getInstance();
2933
$front->registerPlugin(new RabbitMqPlugin());
3034

airtime_mvc/application/controllers/LoginController.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ public function indexAction()
1414
$request = $this->getRequest();
1515

1616
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', 'en_CA'));
17-
if (Zend_Auth::getInstance()->hasIdentity())
17+
$auth = Zend_Auth::getInstance();
18+
19+
if ($auth->hasIdentity())
1820
{
19-
2021
$this->_redirect('Showbuilder');
2122
}
2223

@@ -52,8 +53,7 @@ public function indexAction()
5253
//pass to the adapter the submitted username and password
5354
$authAdapter->setIdentity($username)
5455
->setCredential($password);
55-
56-
$auth = Zend_Auth::getInstance();
56+
5757
$result = $auth->authenticate($authAdapter);
5858
if ($result->isValid()) {
5959
//all info about this user from the login table omit only the password
@@ -66,14 +66,12 @@ public function indexAction()
6666
Application_Model_LoginAttempts::resetAttempts($_SERVER['REMOTE_ADDR']);
6767
Application_Model_Subjects::resetLoginAttempts($username);
6868

69-
$tempSess = new Zend_Session_Namespace("referrer");
70-
$tempSess->referrer = 'login';
71-
7269
//set the user locale in case user changed it in when logging in
7370
Application_Model_Preference::SetUserLocale($locale);
7471

7572
$this->_redirect('Showbuilder');
7673
} else {
74+
7775
$message = _("Wrong username or password provided. Please try again.");
7876
Application_Model_Subjects::increaseLoginAttempts($username);
7977
Application_Model_LoginAttempts::increaseAttempts($_SERVER['REMOTE_ADDR']);
@@ -96,7 +94,8 @@ public function indexAction()
9694

9795
public function logoutAction()
9896
{
99-
Zend_Auth::getInstance()->clearIdentity();
97+
$auth = Zend_Auth::getInstance();
98+
$auth->clearIdentity();
10099
$this->_redirect('showbuilder/index');
101100
}
102101

airtime_mvc/application/controllers/plugins/Acl_plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ public function getErrorPage()
109109
public function preDispatch(Zend_Controller_Request_Abstract $request)
110110
{
111111
$controller = strtolower($request->getControllerName());
112+
Application_Model_Auth::pinSessionToClient(Zend_Auth::getInstance());
112113

113114
if (in_array($controller, array("api", "auth", "locale"))) {
114-
115115
$this->setRoleName("G");
116116
} elseif (!Zend_Auth::getInstance()->hasIdentity()) {
117117

airtime_mvc/application/models/Auth.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,18 @@ final public function generateRandomString($length = 12, $allowed_chars = 'abcde
101101

102102
return $string;
103103
}
104+
105+
/** It is essential to do this before interacting with Zend_Auth otherwise sessions could be shared between
106+
* different copies of Airtime on the same webserver. This essentially pins this session to:
107+
* - The server hostname - including subdomain so we segment multiple Airtime installs on different subdomains
108+
* - The remote IP of the browser - to help prevent session hijacking
109+
* - The client ID - same reason as server hostname
110+
* @param Zend_Auth $auth Get this with Zend_Auth::getInstance().
111+
*/
112+
public static function pinSessionToClient($auth)
113+
{
114+
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : "";
115+
$remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : "";
116+
$auth->setStorage(new Zend_Auth_Storage_Session('Airtime' . $serverName . $remoteAddr . Application_Model_Preference::GetClientId()));
117+
}
104118
}

0 commit comments

Comments
 (0)