CVE-2017-15731 (published 2017-10-22T18:29Z)

In phpMyFAQ before 2.9.9, there is Cross-Site Request Forgery (CSRF) in admin/stat.adminlog.php.

Severity: MEDIUM
CVSS v2 base score: 6.8 (AV:N/AC:M/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 8.8, HIGH (CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-352
cwe_name: Cross-Site Request Forgery (CSRF)
description: The web application does not, or can not, sufficiently verify whether a well-formed, valid, consistent request was intentionally provided by the user who submitted the request.
extended_description: When a web server is designed to receive a request from a client without any mechanism for verifying that it was intentionally sent, then it might be possible for an attacker to trick a client into making an unintentional request to the web server which will be treated as an authentic request. This can be done via a URL, image load, XMLHttpRequest, etc. and can result in exposure of data or unintended code execution.
         

Fix information:
repo_url: https://github.com/thorsten/phpMyFAQ
commit_details: repo_url: https://github.com/thorsten/phpMyFAQ
author: Thorsten Rinne
author_date: 2017-10-02 07:56:00+02:00
msg: Added missing CSRF protection
repository: repo_url: https://github.com/thorsten/phpMyFAQ
repo_name: thorsten/phpMyFAQ
description: phpMyFAQ - Open Source FAQ web application for PHP 8.1+ and MySQL, PostgreSQL and other databases
repo_language: PHP
owner: thorsten
file_changes: filename: stat.adminlog.php
change_type: ModificationType.MODIFY
diff: @@ -35,11 +35,18 @@ if ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'adminlog' == $ac
     $perpage = 15;
     $pages = PMF_Filter::filterInput(INPUT_GET, 'pages', FILTER_VALIDATE_INT);
     $page = PMF_Filter::filterInput(INPUT_GET, 'page', FILTER_VALIDATE_INT, 1);
+    $csrfToken = PMF_Filter::filterInput(INPUT_GET, 'csrf', FILTER_SANITIZE_STRING);
 
     if (is_null($pages)) {
         $pages = round(($logging->getNumberOfEntries() + ($perpage / 3)) / $perpage, 0);
     }
 
+    if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfToken) {
+        $deleteLog = false;
+    } else {
+        $deleteLog = true;
+    }
+
     $start = ($page - 1) * $perpage;
     $ende = $start + $perpage;
 
@@ -66,7 +73,8 @@ if ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'adminlog' == $ac
                 <i aria-hidden="true" class="fa fa-tasks"></i> <?php echo $PMF_LANG['ad_menu_adminlog'];
     ?>
                 <div class="pull-right">
-                    <a class="btn btn-danger" href="?action=deleteadminlog">
+                    <a class="btn btn-danger"
+                       href="?action=deleteadminlog&csrf=<?php echo $user->getCsrfTokenFromSession() ?>">
                         <i aria-hidden="true" class="fa fa-trash"></i> <?php echo $PMF_LANG['ad_adminlog_del_older_30d'] ?>
                     </a>
                 </div>
@@ -122,17 +130,17 @@ if ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'adminlog' == $ac
         ?></td>
             <td><small><?php
             $text = $logging_value['text'];
-        $text = str_replace('Loginerror', $PMF_LANG['ad_log_lger'], $text);
-        $text = str_replace('Session expired', $PMF_LANG['ad_log_sess'], $text);
-        $text = str_replace('Useredit, ', $PMF_LANG['ad_log_edit'], $text);
-        $text = str_replace('Beitragcreatesave', $PMF_LANG['ad_log_crsa'], $text);
-        $text = str_replace('Beitragcreate', $PMF_LANG['ad_log_crea'], $text);
-        $text = str_replace('Usersave, ', $PMF_LANG['ad_log_ussa'], $text);
-        $text = str_replace('Userdel, ', $PMF_LANG['ad_log_usde'], $text);
-        $text = str_replace('Beitragedit, ', $PMF_LANG['ad_log_beed'], $text);
-        $text = str_replace('Beitragdel, ', $PMF_LANG['ad_log_bede'], $text);
-        echo $text;
-        ?></small>
+            $text = str_replace('Loginerror', $PMF_LANG['ad_log_lger'], $text);
+            $text = str_replace('Session expired', $PMF_LANG['ad_log_sess'], $text);
+            $text = str_replace('Useredit, ', $PMF_LANG['ad_log_edit'], $text);
+            $text = str_replace('Beitragcreatesave', $PMF_LANG['ad_log_crsa'], $text);
+            $text = str_replace('Beitragcreate', $PMF_LANG['ad_log_crea'], $text);
+            $text = str_replace('Usersave, ', $PMF_LANG['ad_log_ussa'], $text);
+            $text = str_replace('Userdel, ', $PMF_LANG['ad_log_usde'], $text);
+            $text = str_replace('Beitragedit, ', $PMF_LANG['ad_log_beed'], $text);
+            $text = str_replace('Beitragdel, ', $PMF_LANG['ad_log_bede'], $text);
+            echo $text;
+            ?></small>
             </td>
         </tr>
 <?php
@@ -144,7 +152,7 @@ if ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'adminlog' == $ac
 
 <?php
 
-} elseif ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'deleteadminlog' == $action) {
+} elseif ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'deleteadminlog' == $action && $deleteLog) {
     if ($logging->delete()) {
         printf('<p class="alert alert-success">%s</p>', $PMF_LANG['ad_adminlog_delete_success']);
     } else {

programming_language: PHP