mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-23 12:09:12 +01:00
Don't show personalized menu items until users establish a full session
Summary: Depends on D18792. Fixes T13024. Fixes T89198. Currently, when users are logging in initially (for example, need to enter MFA) we show more menu items than we should. Notably, we may show some personalized/private account details, like the number of unread notifications (probably not relevant) or a user's saved queries (possibly sensitive). At best these are misleading (they won't work yet) and there's an outside possibility they leak a little bit of private data. Instead, nuke everything except "Log Out" when users have partial sessions. Test Plan: Hit a partial session (MFA required, email verification required) and looked at the menu. Only saw "Log Out". {F5297713} Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13024 Differential Revision: https://secure.phabricator.com/D18793
This commit is contained in:
parent
dc62d18b47
commit
e919233b31
4 changed files with 106 additions and 32 deletions
|
@ -10,6 +10,10 @@ final class PhabricatorFileDataController extends PhabricatorFileController {
|
|||
return false;
|
||||
}
|
||||
|
||||
public function shouldAllowPartialSessions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$this->phid = $request->getURIData('phid');
|
||||
|
|
|
@ -9,6 +9,10 @@ final class PeopleMainMenuBarExtension
|
|||
return $viewer->isLoggedIn();
|
||||
}
|
||||
|
||||
public function shouldAllowPartialSessions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getExtensionOrder() {
|
||||
return 1200;
|
||||
}
|
||||
|
@ -65,6 +69,7 @@ final class PeopleMainMenuBarExtension
|
|||
$view = id(new PhabricatorActionListView())
|
||||
->setViewer($viewer);
|
||||
|
||||
if ($this->getIsFullSession()) {
|
||||
$view->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->appendChild($user_view));
|
||||
|
@ -101,6 +106,7 @@ final class PeopleMainMenuBarExtension
|
|||
id(new PhabricatorActionView())
|
||||
->addSigil('logout-item')
|
||||
->setType(PhabricatorActionView::TYPE_DIVIDER));
|
||||
}
|
||||
|
||||
$view->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
|
|
|
@ -5,6 +5,7 @@ abstract class PhabricatorMainMenuBarExtension extends Phobject {
|
|||
private $viewer;
|
||||
private $application;
|
||||
private $controller;
|
||||
private $isFullSession;
|
||||
|
||||
public function setViewer(PhabricatorUser $viewer) {
|
||||
$this->viewer = $viewer;
|
||||
|
@ -33,6 +34,15 @@ abstract class PhabricatorMainMenuBarExtension extends Phobject {
|
|||
return $this->controller;
|
||||
}
|
||||
|
||||
public function setIsFullSession($is_full_session) {
|
||||
$this->isFullSession = $is_full_session;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsFullSession() {
|
||||
return $this->isFullSession;
|
||||
}
|
||||
|
||||
final public function getExtensionKey() {
|
||||
return $this->getPhobjectClassConstant('MAINMENUBARKEY');
|
||||
}
|
||||
|
@ -41,6 +51,10 @@ abstract class PhabricatorMainMenuBarExtension extends Phobject {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function shouldAllowPartialSessions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isExtensionEnabledForViewer(PhabricatorUser $viewer) {
|
||||
if (!$viewer->isLoggedIn()) {
|
||||
return false;
|
||||
|
|
|
@ -46,7 +46,9 @@ final class PhabricatorMainMenuView extends AphrontView {
|
|||
$app_button = '';
|
||||
$aural = null;
|
||||
|
||||
if ($viewer->isLoggedIn() && $viewer->isUserActivated()) {
|
||||
$is_full = $this->isFullSession($viewer);
|
||||
|
||||
if ($is_full) {
|
||||
list($menu, $dropdowns, $aural) = $this->renderNotificationMenu();
|
||||
if (array_filter($menu)) {
|
||||
$alerts[] = $menu;
|
||||
|
@ -54,14 +56,18 @@ final class PhabricatorMainMenuView extends AphrontView {
|
|||
$menu_bar = array_merge($menu_bar, $dropdowns);
|
||||
$app_button = $this->renderApplicationMenuButton();
|
||||
$search_button = $this->renderSearchMenuButton($header_id);
|
||||
} else {
|
||||
} else if (!$viewer->isLoggedIn()) {
|
||||
$app_button = $this->renderApplicationMenuButton();
|
||||
if (PhabricatorEnv::getEnvConfig('policy.allow-public')) {
|
||||
$search_button = $this->renderSearchMenuButton($header_id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($search_button) {
|
||||
$search_menu = $this->renderPhabricatorSearchMenu();
|
||||
} else {
|
||||
$search_menu = null;
|
||||
}
|
||||
|
||||
if ($alerts) {
|
||||
$alerts = javelin_tag(
|
||||
|
@ -84,7 +90,9 @@ final class PhabricatorMainMenuView extends AphrontView {
|
|||
|
||||
$extensions = PhabricatorMainMenuBarExtension::getAllEnabledExtensions();
|
||||
foreach ($extensions as $extension) {
|
||||
$extension->setViewer($viewer);
|
||||
$extension
|
||||
->setViewer($viewer)
|
||||
->setIsFullSession($is_full);
|
||||
|
||||
$controller = $this->getController();
|
||||
if ($controller) {
|
||||
|
@ -96,6 +104,14 @@ final class PhabricatorMainMenuView extends AphrontView {
|
|||
}
|
||||
}
|
||||
|
||||
if (!$is_full) {
|
||||
foreach ($extensions as $key => $extension) {
|
||||
if (!$extension->shouldAllowPartialSessions()) {
|
||||
unset($extensions[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($extensions as $key => $extension) {
|
||||
if (!$extension->isExtensionEnabledForViewer($extension->getViewer())) {
|
||||
unset($extensions[$key]);
|
||||
|
@ -677,4 +693,38 @@ final class PhabricatorMainMenuView extends AphrontView {
|
|||
);
|
||||
}
|
||||
|
||||
private function isFullSession(PhabricatorUser $viewer) {
|
||||
if (!$viewer->isLoggedIn()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$viewer->isUserActivated()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$viewer->hasSession()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$session = $viewer->getSession();
|
||||
if ($session->getIsPartial()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$session->getSignedLegalpadDocuments()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$mfa_key = 'security.require-multi-factor-auth';
|
||||
$need_mfa = PhabricatorEnv::getEnvConfig($mfa_key);
|
||||
if ($need_mfa) {
|
||||
$have_mfa = $viewer->getIsEnrolledInMultiFactor();
|
||||
if (!$have_mfa) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue