CVE-2017-15731: Cross-Site Request Forgery (CSRF) (CWE-352)
value: In phpMyFAQ before 2.9.9, there is Cross-Site Request Forgery (CSRF) in admin/stat.adminlog.php.
CWE 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.
CVSS v3 base score: 8.8
Published: 2017-10-22T18:29Z
Repository: https://github.com/thorsten/phpMyFAQ
Language: PHP
Files changed: phpmyfaq/admin/stat.adminlog.php
Commit date: 2017-10-02 07:56:00 +0200
Commit message: Added missing CSRF protection

Diff: diff --git a/phpmyfaq/admin/stat.adminlog.php b/phpmyfaq/admin/stat.adminlog.php
index 91cce6714..5847c6060 100644
--- a/phpmyfaq/admin/stat.adminlog.php
+++ b/phpmyfaq/admin/stat.adminlog.php
@@ -33,15 +33,22 @@ $logging = new PMF_Logging($faqConfig);
 if ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'adminlog' == $action) {
     $date = new PMF_Date($faqConfig);
     $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;
 
     $baseUrl = sprintf(
         '%s?action=adminlog&amp;page=%d',
@@ -64,11 +71,12 @@ if ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'adminlog' == $ac
         <div class="col-lg-12">
             <h2 class="page-header">
                 <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>
             </h2>
         </div>
@@ -120,21 +128,21 @@ if ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'adminlog' == $ac
         ?></td>
             <td><?php echo $logging_value['ip'];
         ?></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
 
     }
@@ -142,11 +150,11 @@ if ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'adminlog' == $ac
     </tbody>
     </table>
 
 <?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 {
         printf('<p class="alert alert-danger">%s</p>', $PMF_LANG['ad_adminlog_delete_failure']);
     }

Vulnerable code:                     <a class="btn btn-danger" href="?action=deleteadminlog">
        $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>
} elseif ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'deleteadminlog' == $action) {
Fixed code:     $csrfToken = PMF_Filter::filterInput(INPUT_GET, 'csrf', FILTER_SANITIZE_STRING);
    if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfToken) {
        $deleteLog = false;
    } else {
        $deleteLog = true;
    }

                    <a class="btn btn-danger"
                       href="?action=deleteadminlog&csrf=<?php echo $user->getCsrfTokenFromSession() ?>">
            $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>
} elseif ($user->perm->checkRight($user->getUserId(), 'adminlog') && 'deleteadminlog' == $action && $deleteLog) {