Skip to content

Commit 61aafd8

Browse files
author
Kristan Kenney
committed
Ensure token is required to impersonate user
1 parent e52100d commit 61aafd8

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

web/login/index.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,33 @@
1414

1515
// Login as someone else
1616
if (isset($_SESSION['user'])) {
17+
18+
// Default location
1719
if (empty($_GET['loginas']) ){
1820
header("Location: /list/web/");
1921
exit;
2022
}
23+
2124
if ($_SESSION['userContext'] === 'admin' && !empty($_GET['loginas'])) {
22-
exec (HESTIA_CMD . "v-list-user ".escapeshellarg($_GET['loginas'])." json", $output, $return_var);
23-
if ( $return_var == 0 ) {
24-
$data = json_decode(implode('', $output), true);
25-
reset($data);
26-
$_SESSION['look'] = key($data);
27-
$_SESSION['look_alert'] = 'yes';
28-
# Remove current path for filemanager
29-
unset($_SESSION['_sf2_attributes']);
30-
unset($_SESSION['_sf2_meta']);
25+
// Ensure token is passed and matches before granting user impersonation
26+
if ((!$_GET['token']) || ($_SESSION['token'] != $_GET['token'])) {
27+
header('location: /list/user/');
28+
exit();
29+
} else {
30+
exec (HESTIA_CMD . "v-list-user ".escapeshellarg($_GET['loginas'])." json", $output, $return_var);
31+
if ( $return_var == 0 ) {
32+
$data = json_decode(implode('', $output), true);
33+
reset($data);
34+
$_SESSION['look'] = key($data);
35+
$_SESSION['look_alert'] = 'yes';
36+
# Remove current path for filemanager
37+
unset($_SESSION['_sf2_attributes']);
38+
unset($_SESSION['_sf2_meta']);
39+
}
3140
}
3241
}
42+
43+
// Set correct entry point into the panel
3344
if ($_SESSION['userContext'] === 'admin' && empty($_GET['loginas'])) {
3445
header("Location: /list/user/");
3546
} else {

0 commit comments

Comments
 (0)