Skip to content

Commit 6068921

Browse files
committed
Added new security config option cms.enableCsrfProtection
1 parent 6cf1169 commit 6068921

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- List columns now support specifying a `default` option used when the value would otherwise be null.
33
- Implement a custom autoloader for plugins that use composer. Now only one instance of composer is used, all packages are now added to a global pool to prevent double loading and the load order is respected.
44
- The method signature of `Model::save()` has been fixed to match Eloquent.
5+
- Added new security config option `cms.enableCsrfProtection`.
56

67
* **Build 272** (2015-06-27)
78
- Protected images and their thumbnails are now supported in the back-end.

config/cms.php

+12
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,16 @@
250250

251251
'defaultMask' => ['file' => null, 'folder' => null],
252252

253+
/*
254+
|--------------------------------------------------------------------------
255+
| Cross Site Request Forgery (CSRF) Protection
256+
|--------------------------------------------------------------------------
257+
|
258+
| If the CSRF protection is enabled, all "postback" requests are checked
259+
| for a valid security token.
260+
|
261+
*/
262+
263+
'enableCsrfProtection' => false,
264+
253265
];

modules/backend/classes/Controller.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use View;
77
use Flash;
88
use Event;
9+
use Config;
910
use Request;
1011
use Backend;
1112
use Session;
@@ -34,9 +35,9 @@
3435
*/
3536
class Controller extends Extendable
3637
{
38+
use \System\Traits\ViewMaker;
3739
use \System\Traits\AssetMaker;
3840
use \System\Traits\ConfigMaker;
39-
use \System\Traits\ViewMaker;
4041
use \Backend\Traits\WidgetMaker;
4142
use \October\Rain\Support\Traits\Emitter;
4243

@@ -118,11 +119,6 @@ class Controller extends Extendable
118119
*/
119120
protected $statusCode = 200;
120121

121-
/**
122-
* @var bool Determine if submission requests use CSRF protection.
123-
*/
124-
public $useSecurityToken = true;
125-
126122
/**
127123
* Constructor.
128124
*/
@@ -176,7 +172,7 @@ public function run($action = null, $params = [])
176172
/*
177173
* Check security token.
178174
*/
179-
if ($this->useSecurityToken && !$this->verifyCsrfToken()) {
175+
if (!$this->verifyCsrfToken()) {
180176
return Response::make(Lang::get('backend::lang.page.invalid_token.label'), 403);
181177
}
182178

@@ -629,11 +625,16 @@ public function isBackendHintHidden($name)
629625

630626
/**
631627
* Checks the request data / headers for a valid CSRF token.
632-
* Returns false if a valid token is not found.
628+
* Returns false if a valid token is not found. Override this
629+
* method to disable the check.
633630
* @return bool
634631
*/
635632
protected function verifyCsrfToken()
636633
{
634+
if (!Config::get('cms.enableCsrfProtection')) {
635+
return true;
636+
}
637+
637638
if (in_array(Request::method(), ['HEAD', 'GET', 'OPTIONS'])) {
638639
return true;
639640
}

0 commit comments

Comments
 (0)