Skip to content
Snippets Groups Projects
Commit 65cb170b authored by Demian Katz's avatar Demian Katz
Browse files

Security: prevent arbitrary loading of non-configured auth modules.

parent 6b85bea8
Branches
Tags
No related merge requests found
...@@ -55,6 +55,13 @@ class Manager ...@@ -55,6 +55,13 @@ class Manager
*/ */
protected $activeAuth; protected $activeAuth;
/**
* Whitelist of values allowed to be set into $activeAuth
*
* @var array
*/
protected $legalAuthOptions;
/** /**
* VuFind configuration * VuFind configuration
* *
...@@ -108,13 +115,21 @@ class Manager ...@@ -108,13 +115,21 @@ class Manager
public function __construct(Config $config, UserTable $userTable, public function __construct(Config $config, UserTable $userTable,
SessionManager $sessionManager, PluginManager $pm SessionManager $sessionManager, PluginManager $pm
) { ) {
// Store dependencies:
$this->config = $config; $this->config = $config;
$this->activeAuth = isset($config->Authentication->method)
? $config->Authentication->method : null;
$this->userTable = $userTable; $this->userTable = $userTable;
$this->sessionManager = $sessionManager; $this->sessionManager = $sessionManager;
$this->pluginManager = $pm; $this->pluginManager = $pm;
// Set up session:
$this->session = new \Zend\Session\Container('Account'); $this->session = new \Zend\Session\Container('Account');
// Initialize active authentication setting (defaulting to Database
// if no setting passed in):
$method = isset($config->Authentication->method)
? $config->Authentication->method : 'Database';
$this->legalAuthOptions = array($method);
$this->setAuthMethod($method);
} }
/** /**
...@@ -464,6 +479,18 @@ class Manager ...@@ -464,6 +479,18 @@ class Manager
*/ */
public function setAuthMethod($method) public function setAuthMethod($method)
{ {
// If an illegal option was passed in, block it now:
if (!in_array($method, $this->legalAuthOptions)) {
throw new \Exception("Illegal authentication method: $method");
}
// Change the setting:
$this->activeAuth = $method; $this->activeAuth = $method;
// If this method supports switching to a different method, add those
// options to the whitelist:
$this->legalAuthOptions = array_unique(
array_merge($this->legalAuthOptions, $this->getSelectableAuthOptions())
);
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment