mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 20:40:56 +01:00
Actually check CSRF on Password and LDAP forms
Summary: Ref T4339. We didn't previously check `isFormPost()` on these, but now should. Test Plan: Changed csrf token on login, got kicked out. Reviewers: btrahan, chad Reviewed By: chad CC: aran Maniphest Tasks: T4339 Differential Revision: https://secure.phabricator.com/D8051
This commit is contained in:
parent
5b1d9c935a
commit
febc494737
2 changed files with 35 additions and 30 deletions
|
@ -150,25 +150,27 @@ final class PhabricatorAuthProviderLDAP
|
|||
return array($account, $response);
|
||||
}
|
||||
|
||||
try {
|
||||
if (strlen($username) && $has_password) {
|
||||
$adapter = $this->getAdapter();
|
||||
$adapter->setLoginUsername($username);
|
||||
$adapter->setLoginPassword($password);
|
||||
if ($request->isFormPost()) {
|
||||
try {
|
||||
if (strlen($username) && $has_password) {
|
||||
$adapter = $this->getAdapter();
|
||||
$adapter->setLoginUsername($username);
|
||||
$adapter->setLoginPassword($password);
|
||||
|
||||
// TODO: This calls ldap_bind() eventually, which dumps cleartext
|
||||
// passwords to the error log. See note in PhutilAuthAdapterLDAP.
|
||||
// See T3351.
|
||||
// TODO: This calls ldap_bind() eventually, which dumps cleartext
|
||||
// passwords to the error log. See note in PhutilAuthAdapterLDAP.
|
||||
// See T3351.
|
||||
|
||||
DarkConsoleErrorLogPluginAPI::enableDiscardMode();
|
||||
$account_id = $adapter->getAccountID();
|
||||
DarkConsoleErrorLogPluginAPI::disableDiscardMode();
|
||||
} else {
|
||||
throw new Exception("Username and password are required!");
|
||||
DarkConsoleErrorLogPluginAPI::enableDiscardMode();
|
||||
$account_id = $adapter->getAccountID();
|
||||
DarkConsoleErrorLogPluginAPI::disableDiscardMode();
|
||||
} else {
|
||||
throw new Exception("Username and password are required!");
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
// TODO: Make this cleaner.
|
||||
throw $ex;
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
// TODO: Make this cleaner.
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return array($this->loadOrCreateAccount($account_id), $response);
|
||||
|
|
|
@ -163,22 +163,25 @@ final class PhabricatorAuthProviderPassword
|
|||
$account = null;
|
||||
$log_user = null;
|
||||
|
||||
if (!$require_captcha || $captcha_valid) {
|
||||
$username_or_email = $request->getStr('username');
|
||||
if (strlen($username_or_email)) {
|
||||
$user = id(new PhabricatorUser())->loadOneWhere(
|
||||
'username = %s',
|
||||
$username_or_email);
|
||||
if ($request->isFormPost()) {
|
||||
if (!$require_captcha || $captcha_valid) {
|
||||
$username_or_email = $request->getStr('username');
|
||||
if (strlen($username_or_email)) {
|
||||
$user = id(new PhabricatorUser())->loadOneWhere(
|
||||
'username = %s',
|
||||
$username_or_email);
|
||||
|
||||
if (!$user) {
|
||||
$user = PhabricatorUser::loadOneWithEmailAddress($username_or_email);
|
||||
}
|
||||
if (!$user) {
|
||||
$user = PhabricatorUser::loadOneWithEmailAddress(
|
||||
$username_or_email);
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
$envelope = new PhutilOpaqueEnvelope($request->getStr('password'));
|
||||
if ($user->comparePassword($envelope)) {
|
||||
$account = $this->loadOrCreateAccount($user->getPHID());
|
||||
$log_user = $user;
|
||||
if ($user) {
|
||||
$envelope = new PhutilOpaqueEnvelope($request->getStr('password'));
|
||||
if ($user->comparePassword($envelope)) {
|
||||
$account = $this->loadOrCreateAccount($user->getPHID());
|
||||
$log_user = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue