security: CSRF
This addresses a report submitted by Khaled M. Alshammri (@ik0z) in regards to CSRF enforcement for state-changing request methods.
This commit is contained in:
@@ -67,8 +67,9 @@ if($thisclient && $thisclient->getId() && $thisclient->isValid()){
|
||||
}
|
||||
|
||||
/******* CSRF Protectin *************/
|
||||
// Enforce CSRF protection for POSTS
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !$ost->checkCSRFToken()) {
|
||||
// Enforce CSRF protection for state-changing methods
|
||||
if (in_array($_SERVER['REQUEST_METHOD'], ['POST', 'PUT', 'PATCH', 'DELETE'])
|
||||
&& !$ost->checkCSRFToken()) {
|
||||
Http::redirect('index.php');
|
||||
//just incase redirect fails
|
||||
die('Action denied (400)!');
|
||||
|
||||
@@ -104,8 +104,9 @@ define('SESSION_MAXLIFE', $thisstaff->getMaxIdleTime());
|
||||
$thisstaff->refreshSession();
|
||||
|
||||
/******* CSRF Protectin *************/
|
||||
// Enforce CSRF protection for POSTS
|
||||
if ($_POST && !$ost->checkCSRFToken()) {
|
||||
// Enforce CSRF protection for state-changing methods
|
||||
if (in_array($_SERVER['REQUEST_METHOD'], ['POST', 'PUT', 'PATCH', 'DELETE'])
|
||||
&& !$ost->checkCSRFToken()) {
|
||||
Http::response(400, __('Valid CSRF Token Required'));
|
||||
exit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user