Skip to content

Commit f51eef2

Browse files
authored
use the same csrf token for all the user become forms (#494)
1 parent 8654de4 commit f51eef2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

webroot/admin/user-mgmt.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use UnityWebPortal\lib\UnityHTTPD;
66
use UnityWebPortal\lib\UserFlag;
7+
use UnityWebPortal\lib\CSRFToken;
78

89
if (!$USER->getFlag(UserFlag::ADMIN)) {
910
UnityHTTPD::forbidden("not an admin", "You are not an admin.");
@@ -54,6 +55,7 @@ class="filterSearch"
5455
"mail" => ["(not found)"]
5556
]
5657
);
58+
$csrf_token = htmlspecialchars(CSRFToken::generate());
5759
usort($user_attributes, fn ($a, $b) => strcmp($a["uid"][0], $b["uid"][0]));
5860
foreach ($user_attributes as $attributes) {
5961
$uid = $attributes["uid"][0];
@@ -80,10 +82,9 @@ class="filterSearch"
8082
}
8183
echo "</td>";
8284
echo "<td>";
83-
$CSRFTokenHiddenFormInput = UnityHTTPD::getCSRFTokenHiddenFormInput();
8485
echo "<form class='viewAsUserForm' action='' method='POST'
8586
onsubmit='return confirm(\"Are you sure you want to switch to the user $uid?\");'>
86-
$CSRFTokenHiddenFormInput
87+
<input type='hidden' name='csrf_token' value='$csrf_token'>
8788
<input type='hidden' name='form_type' value='viewAsUser'>
8889
<input type='hidden' name='uid' value='$uid'>
8990
<input type='submit' name='action' value='Access'>

0 commit comments

Comments
 (0)