Skip to content

Commit

Permalink
fix: terminate user sessions for user with changed permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Sep 22, 2023
1 parent 62b9ef1 commit 5f43786
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 1 addition & 2 deletions phpmyfaq/admin/api/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@

case 'activate_user':
$postData = json_decode(file_get_contents('php://input', true));

if (!Token::getInstance()->verifyToken('user', $postData->csrfToken)) {
if (!Token::getInstance()->verifyToken('activate-user', $postData->csrfToken)) {
$response->setStatusCode(Response::HTTP_UNAUTHORIZED);
$response->setData(['error' => Translation::get('err_NotAuth')]);
$response->send();
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/assets/src/user/user-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { addElement } from '../../../../assets/src/utils';

const activateUser = (userId, csrfToken) => {
fetch('index.php?action=ajax&ajax=user&ajaxaction=delete_user', {
fetch('index.php?action=ajax&ajax=user&ajaxaction=activate_user', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
Expand Down
3 changes: 3 additions & 0 deletions phpmyfaq/admin/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@
foreach ($userRights as $rightId) {
$perm->grantUserRight($userId, $rightId);
}

$idUser = $user->getUserById($userId, true);
// Terminate session in case of different permissions after the update
$user->terminateSessionId();
$message .= sprintf(
'<p class="alert alert-success">%s <strong>%s</strong> %s</p>',
Translation::get('ad_msg_savedsuc_1'),
Expand Down
15 changes: 15 additions & 0 deletions phpmyfaq/src/phpMyFAQ/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1037,4 +1037,19 @@ public function setSuperAdmin(bool $isSuperAdmin): bool

return false;
}

/**
* Terminates the session ID of user
* @return bool
*/
public function terminateSessionId(): bool
{
$update = sprintf(
"UPDATE %sfaquser SET session_id = '' WHERE user_id = %d",
Database::getTablePrefix(),
$this->userId
);

return (bool) $this->config->getDb()->query($update);
}
}

0 comments on commit 5f43786

Please # to comment.