2015-09-03 10:04:42 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
final class PhabricatorHighSecurityRequestExceptionHandler
|
|
|
|
|
extends PhabricatorRequestExceptionHandler {
|
|
|
|
|
|
|
|
|
|
public function getRequestExceptionHandlerPriority() {
|
|
|
|
|
return 310000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getRequestExceptionHandlerDescription() {
|
|
|
|
|
return pht(
|
|
|
|
|
'Handles high security exceptions which occur when a user needs '.
|
|
|
|
|
'to present MFA credentials to take an action.');
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 12:51:00 -07:00
|
|
|
public function canHandleRequestThrowable(
|
2015-09-03 10:04:42 -07:00
|
|
|
AphrontRequest $request,
|
2017-06-19 12:51:00 -07:00
|
|
|
$throwable) {
|
2015-09-03 10:04:42 -07:00
|
|
|
|
|
|
|
|
if (!$this->isPhabricatorSite($request)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 12:51:00 -07:00
|
|
|
return ($throwable instanceof PhabricatorAuthHighSecurityRequiredException);
|
2015-09-03 10:04:42 -07:00
|
|
|
}
|
|
|
|
|
|
2017-06-19 12:51:00 -07:00
|
|
|
public function handleRequestThrowable(
|
2015-09-03 10:04:42 -07:00
|
|
|
AphrontRequest $request,
|
2017-06-19 12:51:00 -07:00
|
|
|
$throwable) {
|
2015-09-03 10:04:42 -07:00
|
|
|
|
|
|
|
|
$viewer = $this->getViewer($request);
|
|
|
|
|
|
|
|
|
|
$form = id(new PhabricatorAuthSessionEngine())->renderHighSecurityForm(
|
2017-06-19 12:51:00 -07:00
|
|
|
$throwable->getFactors(),
|
|
|
|
|
$throwable->getFactorValidationResults(),
|
2015-09-03 10:04:42 -07:00
|
|
|
$viewer,
|
|
|
|
|
$request);
|
|
|
|
|
|
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
|
->setUser($viewer)
|
|
|
|
|
->setTitle(pht('Entering High Security'))
|
|
|
|
|
->setShortTitle(pht('Security Checkpoint'))
|
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
|
|
|
->addHiddenInput(AphrontRequest::TYPE_HISEC, true)
|
|
|
|
|
->setErrors(
|
|
|
|
|
array(
|
|
|
|
|
pht(
|
|
|
|
|
'You are taking an action which requires you to enter '.
|
|
|
|
|
'high security.'),
|
|
|
|
|
))
|
|
|
|
|
->appendParagraph(
|
|
|
|
|
pht(
|
|
|
|
|
'High security mode helps protect your account from security '.
|
|
|
|
|
'threats, like session theft or someone messing with your stuff '.
|
|
|
|
|
'while you\'re grabbing a coffee. To enter high security mode, '.
|
|
|
|
|
'confirm your credentials.'))
|
|
|
|
|
->appendChild($form->buildLayoutView())
|
|
|
|
|
->appendParagraph(
|
|
|
|
|
pht(
|
|
|
|
|
'Your account will remain in high security mode for a short '.
|
|
|
|
|
'period of time. When you are finished taking sensitive '.
|
|
|
|
|
'actions, you should leave high security.'))
|
|
|
|
|
->setSubmitURI($request->getPath())
|
2017-06-19 12:51:00 -07:00
|
|
|
->addCancelButton($throwable->getCancelURI())
|
2015-09-03 10:04:42 -07:00
|
|
|
->addSubmitButton(pht('Enter High Security'));
|
|
|
|
|
|
|
|
|
|
$request_parameters = $request->getPassthroughRequestParameters(
|
|
|
|
|
$respect_quicksand = true);
|
|
|
|
|
foreach ($request_parameters as $key => $value) {
|
|
|
|
|
$dialog->addHiddenInput($key, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $dialog;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|