diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 7c3e591ae05..0cab8e67ba9 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3991,7 +3991,7 @@ class Form closeOnEscape: false, buttons: { "'.dol_escape_js($langs->transnoentities("Yes")).'": function() { - var options = "token='.urlencode($_SESSION['newtoken']).'"; + var options = "&token='.urlencode($_SESSION['newtoken']).'"; var inputok = '.json_encode($inputok).'; var pageyes = "'.dol_escape_js(! empty($pageyes)?$pageyes:'').'"; if (inputok.length>0) { @@ -4010,7 +4010,7 @@ class Form $(this).dialog("close"); }, "'.dol_escape_js($langs->transnoentities("No")).'": function() { - var options = "token='.urlencode($_SESSION['newtoken']).'"; + var options = "&token='.urlencode($_SESSION['newtoken']).'"; var inputko = '.json_encode($inputko).'; var pageno="'.dol_escape_js(! empty($pageno)?$pageno:'').'"; if (inputko.length>0) { @@ -4049,7 +4049,7 @@ class Form if (empty($disableformtag)) $formconfirm.= '
'."\n"; $formconfirm.= ''."\n"; - if (empty($disableformtag)) $formconfirm.= ''."\n"; + $formconfirm.= ''."\n"; $formconfirm.= ''."\n"; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index b4aca36f596..498a1166858 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -373,24 +373,27 @@ if (! defined('NOTOKENRENEWAL')) $token = dol_hash(uniqid(mt_rand(), true)); // Generates a hash of a random number $_SESSION['newtoken'] = $token; } +// Check token if ((! defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && ! empty($conf->global->MAIN_SECURITY_CSRF_WITH_TOKEN)) || defined('CSRFCHECK_WITH_TOKEN')) // Check validity of token, only if option MAIN_SECURITY_CSRF_WITH_TOKEN enabled or if constant CSRFCHECK_WITH_TOKEN is set { - if ($_SERVER['REQUEST_METHOD'] == 'POST' && ! GETPOST('token','alpha')) // Note, offender can still send request by GET + if ($_SERVER['REQUEST_METHOD'] == 'POST' && ! GETPOSTISSET('token')) // Note, offender can still send request by GET { print "Access refused by CSRF protection in main.inc.php. Token not provided.\n"; print "If you access your server behind a proxy using url rewriting, you might check that all HTTP header is propagated (or add the line \$dolibarr_nocsrfcheck=1 into your conf.php file).\n"; die; } - if ($_SERVER['REQUEST_METHOD'] === 'POST') // This test must be after loading $_SESSION['token']. + + //if ($_SERVER['REQUEST_METHOD'] === 'POST') // This test must be after loading $_SESSION['token']. + //{ + if (GETPOSTISSET('token') && GETPOST('token', 'alpha') != $_SESSION['token']) { - if (GETPOST('token', 'alpha') != $_SESSION['token']) - { - dol_syslog("Invalid token in ".$_SERVER['HTTP_REFERER'].", action=".GETPOST('action','aZ09').", _POST['token']=".GETPOST('token','alpha').", _SESSION['token']=".$_SESSION['token'], LOG_WARNING); - //print 'Unset POST by CSRF protection in main.inc.php.'; // Do not output anything because this create problems when using the BACK button on browsers. - unset($_POST); - } + dol_syslog("Invalid token, so we disable POST and some GET parameters - referer=".$_SERVER['HTTP_REFERER'].", action=".GETPOST('action','aZ09').", _GET|POST['token']=".GETPOST('token','alpha').", _SESSION['token']=".$_SESSION['token'], LOG_WARNING); + //print 'Unset POST by CSRF protection in main.inc.php.'; // Do not output anything because this create problems when using the BACK button on browsers. + unset($_POST); + unset($_GET['confirm']); } + //} } // Disable modules (this must be after session_start and after conf has been loaded) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 05e6e6f54d3..103e82a04bc 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -145,15 +145,25 @@ if (empty($reshook)) { } } - if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser) { - if ($id <> $user->id) { + if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser) + { + if ($id <> $user->id) + { + if (! GETPOSTISSET('token')) + { + print 'Error, token required for this critical operation'; + exit; + } + $object = new User($db); $object->fetch($id); + $result = $object->delete($user); if ($result < 0) { $langs->load("errors"); setEventMessages($langs->trans("ErrorUserCannotBeDelete"), null, 'errors'); } else { + setEventMessages($langs->trans("RecordDeleted"), null); header("Location: ".DOL_URL_ROOT."/user/list.php?restore_lastsearch_values=1"); exit; }