mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
Use new modular temporary auth token constants in one-time login and password reset flows
Summary: Ref T10603. This converts existing hard-codes to modular constants. Also removes one small piece of code duplication. Test Plan: - Performed one-time logins. - Performed a password reset. - Verified temporary tokens were revoked properly. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10603 Differential Revision: https://secure.phabricator.com/D15476
This commit is contained in:
parent
cf15e0de43
commit
8e3ea4e034
4 changed files with 18 additions and 31 deletions
|
@ -105,23 +105,17 @@ final class PhabricatorAuthOneTimeLoginController
|
||||||
// the link in the "Welcome" email is good enough, without requiring users
|
// the link in the "Welcome" email is good enough, without requiring users
|
||||||
// to go through a second round of email verification.
|
// to go through a second round of email verification.
|
||||||
|
|
||||||
|
$editor = id(new PhabricatorUserEditor())
|
||||||
|
->setActor($target_user);
|
||||||
|
|
||||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
||||||
// Nuke the token and all other outstanding password reset tokens.
|
// Nuke the token and all other outstanding password reset tokens.
|
||||||
// There is no particular security benefit to destroying them all, but
|
// There is no particular security benefit to destroying them all, but
|
||||||
// it should reduce HackerOne reports of nebulous harm.
|
// it should reduce HackerOne reports of nebulous harm.
|
||||||
|
$editor->revokePasswordResetLinks($target_user);
|
||||||
PhabricatorAuthTemporaryToken::revokeTokens(
|
|
||||||
$target_user,
|
|
||||||
array($target_user->getPHID()),
|
|
||||||
array(
|
|
||||||
PhabricatorAuthSessionEngine::ONETIME_TEMPORARY_TOKEN_TYPE,
|
|
||||||
PhabricatorAuthSessionEngine::PASSWORD_TEMPORARY_TOKEN_TYPE,
|
|
||||||
));
|
|
||||||
|
|
||||||
if ($target_email) {
|
if ($target_email) {
|
||||||
id(new PhabricatorUserEditor())
|
$editor->verifyEmail($target_user, $target_email);
|
||||||
->setActor($target_user)
|
|
||||||
->verifyEmail($target_user, $target_email);
|
|
||||||
}
|
}
|
||||||
unset($unguarded);
|
unset($unguarded);
|
||||||
|
|
||||||
|
@ -133,12 +127,13 @@ final class PhabricatorAuthOneTimeLoginController
|
||||||
// We're going to let the user reset their password without knowing
|
// We're going to let the user reset their password without knowing
|
||||||
// the old one. Generate a one-time token for that.
|
// the old one. Generate a one-time token for that.
|
||||||
$key = Filesystem::readRandomCharacters(16);
|
$key = Filesystem::readRandomCharacters(16);
|
||||||
|
$password_type =
|
||||||
|
PhabricatorAuthPasswordResetTemporaryTokenType::TOKENTYPE;
|
||||||
|
|
||||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
||||||
id(new PhabricatorAuthTemporaryToken())
|
id(new PhabricatorAuthTemporaryToken())
|
||||||
->setObjectPHID($target_user->getPHID())
|
->setObjectPHID($target_user->getPHID())
|
||||||
->setTokenType(
|
->setTokenType($password_type)
|
||||||
PhabricatorAuthSessionEngine::PASSWORD_TEMPORARY_TOKEN_TYPE)
|
|
||||||
->setTokenExpires(time() + phutil_units('1 hour in seconds'))
|
->setTokenExpires(time() + phutil_units('1 hour in seconds'))
|
||||||
->setTokenCode(PhabricatorHash::digest($key))
|
->setTokenCode(PhabricatorHash::digest($key))
|
||||||
->save();
|
->save();
|
||||||
|
|
|
@ -39,17 +39,6 @@ final class PhabricatorAuthSessionEngine extends Phobject {
|
||||||
const KIND_UNKNOWN = '?';
|
const KIND_UNKNOWN = '?';
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Temporary tokens for one time logins.
|
|
||||||
*/
|
|
||||||
const ONETIME_TEMPORARY_TOKEN_TYPE = 'login:onetime';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Temporary tokens for password recovery after one time login.
|
|
||||||
*/
|
|
||||||
const PASSWORD_TEMPORARY_TOKEN_TYPE = 'login:password';
|
|
||||||
|
|
||||||
const ONETIME_RECOVER = 'recover';
|
const ONETIME_RECOVER = 'recover';
|
||||||
const ONETIME_RESET = 'reset';
|
const ONETIME_RESET = 'reset';
|
||||||
const ONETIME_WELCOME = 'welcome';
|
const ONETIME_WELCOME = 'welcome';
|
||||||
|
@ -642,11 +631,12 @@ final class PhabricatorAuthSessionEngine extends Phobject {
|
||||||
|
|
||||||
$key = Filesystem::readRandomCharacters(32);
|
$key = Filesystem::readRandomCharacters(32);
|
||||||
$key_hash = $this->getOneTimeLoginKeyHash($user, $email, $key);
|
$key_hash = $this->getOneTimeLoginKeyHash($user, $email, $key);
|
||||||
|
$onetime_type = PhabricatorAuthOneTimeLoginTemporaryTokenType::TOKENTYPE;
|
||||||
|
|
||||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
||||||
id(new PhabricatorAuthTemporaryToken())
|
id(new PhabricatorAuthTemporaryToken())
|
||||||
->setObjectPHID($user->getPHID())
|
->setObjectPHID($user->getPHID())
|
||||||
->setTokenType(self::ONETIME_TEMPORARY_TOKEN_TYPE)
|
->setTokenType($onetime_type)
|
||||||
->setTokenExpires(time() + phutil_units('1 day in seconds'))
|
->setTokenExpires(time() + phutil_units('1 day in seconds'))
|
||||||
->setTokenCode($key_hash)
|
->setTokenCode($key_hash)
|
||||||
->save();
|
->save();
|
||||||
|
@ -685,11 +675,12 @@ final class PhabricatorAuthSessionEngine extends Phobject {
|
||||||
$key = null) {
|
$key = null) {
|
||||||
|
|
||||||
$key_hash = $this->getOneTimeLoginKeyHash($user, $email, $key);
|
$key_hash = $this->getOneTimeLoginKeyHash($user, $email, $key);
|
||||||
|
$onetime_type = PhabricatorAuthOneTimeLoginTemporaryTokenType::TOKENTYPE;
|
||||||
|
|
||||||
return id(new PhabricatorAuthTemporaryTokenQuery())
|
return id(new PhabricatorAuthTemporaryTokenQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withObjectPHIDs(array($user->getPHID()))
|
->withObjectPHIDs(array($user->getPHID()))
|
||||||
->withTokenTypes(array(self::ONETIME_TEMPORARY_TOKEN_TYPE))
|
->withTokenTypes(array($onetime_type))
|
||||||
->withTokenCodes(array($key_hash))
|
->withTokenCodes(array($key_hash))
|
||||||
->withExpired(false)
|
->withExpired(false)
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
|
@ -700,7 +700,7 @@ final class PhabricatorUserEditor extends PhabricatorEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function revokePasswordResetLinks(PhabricatorUser $user) {
|
public function revokePasswordResetLinks(PhabricatorUser $user) {
|
||||||
// Revoke any outstanding password reset links. If an attacker compromises
|
// Revoke any outstanding password reset links. If an attacker compromises
|
||||||
// an account, changes the email address, and sends themselves a password
|
// an account, changes the email address, and sends themselves a password
|
||||||
// reset link, it could otherwise remain live for a short period of time
|
// reset link, it could otherwise remain live for a short period of time
|
||||||
|
@ -710,8 +710,8 @@ final class PhabricatorUserEditor extends PhabricatorEditor {
|
||||||
$user,
|
$user,
|
||||||
array($user->getPHID()),
|
array($user->getPHID()),
|
||||||
array(
|
array(
|
||||||
PhabricatorAuthSessionEngine::ONETIME_TEMPORARY_TOKEN_TYPE,
|
PhabricatorAuthOneTimeLoginTemporaryTokenType::TOKENTYPE,
|
||||||
PhabricatorAuthSessionEngine::PASSWORD_TEMPORARY_TOKEN_TYPE,
|
PhabricatorAuthPasswordResetTemporaryTokenType::TOKENTYPE,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,13 +40,14 @@ final class PhabricatorPasswordSettingsPanel extends PhabricatorSettingsPanel {
|
||||||
// the workflow from a password reset email.
|
// the workflow from a password reset email.
|
||||||
|
|
||||||
$key = $request->getStr('key');
|
$key = $request->getStr('key');
|
||||||
|
$password_type = PhabricatorAuthPasswordResetTemporaryTokenType::TOKENTYPE;
|
||||||
|
|
||||||
$token = null;
|
$token = null;
|
||||||
if ($key) {
|
if ($key) {
|
||||||
$token = id(new PhabricatorAuthTemporaryTokenQuery())
|
$token = id(new PhabricatorAuthTemporaryTokenQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withObjectPHIDs(array($user->getPHID()))
|
->withObjectPHIDs(array($user->getPHID()))
|
||||||
->withTokenTypes(
|
->withTokenTypes(array($password_type))
|
||||||
array(PhabricatorAuthSessionEngine::PASSWORD_TEMPORARY_TOKEN_TYPE))
|
|
||||||
->withTokenCodes(array(PhabricatorHash::digest($key)))
|
->withTokenCodes(array(PhabricatorHash::digest($key)))
|
||||||
->withExpired(false)
|
->withExpired(false)
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
Loading…
Reference in a new issue