Skip to content

Commit 224b7d9

Browse files
committed
πŸ”’ Restrict demo endpoint access to authorized operators or E2E secret
- πŸ›‘οΈ Demo URL is publicly reachable, so gate it behind either a logged-in operator with the "lhchat"/"use" permission or an anonymous request presenting an e2e_secret matching the E2E_SECRET environment variable - πŸ”‘ Use hash_equals for constant-time secret comparison to prevent timing attacks on the shared E2E token - 🚫 Redirect unauthenticated visitors to the login page and return a no-permission response for logged-in users lacking access, preserving the previous behavior - βž• Whitelist e2e_secret as an allowed uparam and drop the global "use" function requirement so the e2e path can be evaluated inside the view
1 parent 2859fb5 commit 224b7d9

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

β€Žlhc_web/modules/lhchat/demo.phpβ€Ž

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,36 @@
99
// Disable online tracking for demo by session cookies
1010
$_GET['cd'] = 1;
1111

12+
// Demo URL is public. Access is granted either to a logged in operator having the
13+
// same required permission as before ("lhchat"/"use") or to an anonymous request
14+
// providing a get parameter matching the E2E_SECRET environment variable.
15+
$e2eSecret = getenv('E2E_SECRET');
16+
17+
$e2eSecretProvided = isset($_GET['e2e_secret'])
18+
? $_GET['e2e_secret']
19+
: (isset($Params['user_parameters_unordered']['e2e_secret']) ? $Params['user_parameters_unordered']['e2e_secret'] : null);
20+
21+
$e2eAccessGranted = ($e2eSecret !== false && $e2eSecret !== '' && $e2eSecretProvided !== null && is_scalar($e2eSecretProvided) && hash_equals((string)$e2eSecret, (string)$e2eSecretProvided));
22+
23+
if ($e2eAccessGranted === false) {
24+
25+
$currentUser = erLhcoreClassUser::instance();
26+
27+
if ($currentUser->hasAccessTo('lhchat', array('use'), true) === false) {
28+
29+
// Not logged in - redirect to the login page just like before
30+
if ($currentUser->isLogged() === false) {
31+
erLhcoreClassModule::redirect('user/login', '/(r)/' . rawurlencode(base64_encode(self::$currentModuleName . '/' . self::$currentView)));
32+
exit;
33+
}
34+
35+
// Logged in, but without the required permission
36+
include_once('modules/lhkernel/nopermission.php');
37+
$Result['pagelayout'] = 'login';
38+
return;
39+
}
40+
}
41+
1242
if ($Params['user_parameters_unordered']['department'] === null) {
1343

1444
$startData = erLhcoreClassModelChatConfig::fetch('start_chat_data');

β€Žlhc_web/modules/lhchat/module.phpβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,8 @@
579579

580580
$ViewList['demo'] = array (
581581
'params' => array(),
582-
'uparams' => array('sound','id','hash','department','theme','mobile','vid','identifier','inv','survey','priority','operator','leaveamessage','mode','bot','scope','fs','trigger','encrypted','debug'),
582+
'uparams' => array('sound','id','hash','department','theme','mobile','vid','identifier','inv','survey','priority','operator','leaveamessage','mode','bot','scope','fs','trigger','encrypted','debug','e2e_secret'),
583583
'multiple_arguments' => array('department'),
584-
'functions' => array( 'use' ),
585584
);
586585

587586
$ViewList['chatwidget'] = array (

0 commit comments

Comments
Β (0)