diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 1732e795990..eac673e5143 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -302,13 +302,13 @@ if (! defined('NOTOKENRENEWAL')) if (isset($_SESSION['newtoken'])) $_SESSION['token'] = $_SESSION['newtoken']; $_SESSION['newtoken'] = $token; } -if (! empty($conf->global->MAIN_SECURITY_CSRF)) // Check validity of token, only if option enabled (this option breaks some features sometimes) +if (! defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && ! empty($conf->global->MAIN_SECURITY_CSRF_WITH_TOKEN)) // Check validity of token, only if option enabled (this option breaks some features sometimes) { - if (isset($_POST['token']) && isset($_SESSION['token'])) + if ($_SERVER['REQUEST_METHOD'] === 'POST') { - if (($_POST['token'] != $_SESSION['token'])) + if (GETPOST('token') != $_SESSION['token']) { - dol_syslog("Invalid token in ".$_SERVER['HTTP_REFERER'].", action=".GETPOST('action').", _POST['token']=".GETPOST('token').", _SESSION['token']=".$_SESSION['token'],LOG_WARNING); + dol_syslog("Invalid token in ".$_SERVER['HTTP_REFERER'].", action=".GETPOST('action').", _POST['token']=".GETPOST('token').", _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); }