Skip to content

Commit 07b8e76

Browse files
committed
Require back office site access
1 parent 1fb4b3f commit 07b8e76

6 files changed

Lines changed: 61 additions & 1 deletion

File tree

‎lhc_web/lib/core/lhuser/lhuserutils.php‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@ public static function isValidRedirectPath($path)
5454
return true;
5555
}
5656

57+
/**
58+
* Site accesses from which an operator (back office) login is allowed.
59+
* Same rules as user/login applies.
60+
*
61+
* @return array
62+
*/
63+
public static function getLoginSiteAccess()
64+
{
65+
$adminSiteAccess = erConfigClassLhConfig::getInstance()->getSetting('site', 'default_admin_site_access', false);
66+
67+
$possibleLoginSiteAccess = is_array($adminSiteAccess) ? $adminSiteAccess : array('site_admin');
68+
69+
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('user.login_site_access', array('loginSiteAccess' => & $possibleLoginSiteAccess));
70+
71+
return $possibleLoginSiteAccess;
72+
}
73+
74+
/**
75+
* Endpoints which log an operator in without a permission check (hash/token based links)
76+
* have to be served from a back office site access only, just like user/login does.
77+
*
78+
* @return bool
79+
*/
80+
public static function validateLoginSiteAccess()
81+
{
82+
return in_array(erLhcoreClassSystem::instance()->SiteAccess, self::getLoginSiteAccess(), true);
83+
}
84+
5785
public static function updateStats($userlist)
5886
{
5987
$remap = array();

‎lhc_web/modules/lhchat/accept.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php
22

3+
// Accepting a chat logs an operator in without a permission check, so it's allowed only on a back office site access
4+
if (!erLhcoreClassUserUtils::validateLoginSiteAccess()) {
5+
erLhcoreClassModule::redirect('user/login');
6+
exit;
7+
}
8+
39
$cfgSite = erConfigClassLhConfig::getInstance();
410
$secretHash = $cfgSite->getSetting( 'site', 'secrethash' );
511

‎lhc_web/modules/lhrestapi/loginbytoken.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
try {
88

9+
// Browser login starts a session without a permission check, so it's allowed only on a back office site access
10+
if ($modeAPI == false && erLhcoreClassUserUtils::validateLoginSiteAccess() == false) {
11+
throw new Exception('Invalid back office URL');
12+
}
13+
914
if (!isset($_GET['token']) || !is_string($_GET['token']) || trim($_GET['token']) === '') {
1015
throw new Exception('Token not found!');
1116
}

‎lhc_web/modules/lhuser/autologinuser.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
// Just extra security
44
header('X-Robots-Tag: noindex,nofollow');
55

6+
// Autologin logs an operator in without a permission check, so it's allowed only on a back office site access
7+
if (!erLhcoreClassUserUtils::validateLoginSiteAccess()) {
8+
$tpl = erLhcoreClassTemplate::getInstance( 'lhkernel/validation_error_autologin_user.tpl.php');
9+
$tpl->set('errors',array(erTranslationClassLhTranslation::getInstance()->getTranslation('user/login','Invalid back office URL')));
10+
$Result['content'] = $tpl->fetch();
11+
$Result['pagelayout'] = 'login';
12+
return;
13+
}
14+
615
$currentUser = erLhcoreClassUser::instance();
716
$instance = erLhcoreClassSystem::instance();
817

‎lhc_web/modules/lhuser/loginasuser.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
// Login as user logs an operator in without a permission check, so it's allowed only on a back office site access
4+
if (!erLhcoreClassUserUtils::validateLoginSiteAccess()) {
5+
$tpl = erLhcoreClassTemplate::getInstance( 'lhkernel/validation_error_autologin_user.tpl.php');
6+
$tpl->set('errors',array(erTranslationClassLhTranslation::getInstance()->getTranslation('user/login','Invalid back office URL')));
7+
$Result['content'] = $tpl->fetch();
8+
$Result['pagelayout'] = 'login';
9+
return;
10+
}
11+
312
$user = erLhcoreClassModelUser::fetch((int)$Params['user_parameters']['id']);
413

514
$hash = $Params['user_parameters_unordered']['hash'];

‎lhc_web/modules/lhuser/updatepassword.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
$ts = (int)$Params['user_parameters']['ts'];
77
$hash = $Params['user_parameters']['hash'];
88

9-
if ($ts > time()) {
9+
// Password update logs the user in without a permission check, so it's allowed only on a back office site access
10+
if (!erLhcoreClassUserUtils::validateLoginSiteAccess()) {
11+
$tpl->set('errors', array(erTranslationClassLhTranslation::getInstance()->getTranslation('user/login','Invalid back office URL')));
12+
} elseif ($ts > time()) {
1013

1114
$secretHash = erConfigClassLhConfig::getInstance()->getSetting( 'site', 'secrethash' );
1215
$hashToVerify = hash_hmac('sha256', implode(',', array($userId,$ts)), $secretHash);

0 commit comments

Comments
 (0)