Skip to content

Commit

Permalink
Added missing CSRF protection
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Oct 1, 2017
1 parent cce47f9 commit fa26c52
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions phpmyfaq/admin/stat.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<h2 class="page-header">
<i aria-hidden="true" class="fa fa-tasks"></i> <?php echo $PMF_LANG['ad_stat_sess'] ?>
<div class="pull-right">
<a class="btn btn-danger" href="?action=clear-visits">
<a class="btn btn-danger"
href="?action=clear-visits&csrf=<?php echo $user->getCsrfTokenFromSession() ?>">
<i aria-hidden="true" class="fa fa-trash"></i> <?php echo $PMF_LANG['ad_clear_all_visits'] ?>
</a>
</div>
Expand All @@ -47,12 +48,19 @@
$visits = new PMF_Visits($faqConfig);
$statdelete = PMF_Filter::filterInput(INPUT_POST, 'statdelete', FILTER_SANITIZE_STRING);
$month = PMF_Filter::filterInput(INPUT_POST, 'month', FILTER_SANITIZE_STRING);
$csrfToken = PMF_Filter::filterInput(INPUT_POST, 'csrf', FILTER_SANITIZE_STRING);
$csrfTokenFromPost = PMF_Filter::filterInput(INPUT_POST, 'csrf', FILTER_SANITIZE_STRING);
$csrfTokenFromGet = PMF_Filter::filterInput(INPUT_GET, 'csrf', FILTER_SANITIZE_STRING);

if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfToken) {
if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfTokenFromPost) {
$statdelete = null;
}

if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfTokenFromGet) {
$clearVisits = false;
} else {
$clearVisits = true;
}

// Delete sessions and session files
if (!is_null($statdelete) && !is_null($month)) {
$dir = opendir(PMF_ROOT_DIR.'/data');
Expand Down Expand Up @@ -80,7 +88,7 @@
}

// Reset all visits and sessions
if ('clear-visits' === $action) {
if ('clear-visits' === $action && $clearVisits) {

// Clear visits
$visits->resetAll();
Expand Down

0 comments on commit fa26c52

Please sign in to comment.