Skip to content

Commit

Permalink
Added new security config option cms.enableCsrfProtection
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Jul 3, 2015
1 parent 6cf1169 commit 6068921
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- List columns now support specifying a `default` option used when the value would otherwise be null.
- 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.
- The method signature of `Model::save()` has been fixed to match Eloquent.
- Added new security config option `cms.enableCsrfProtection`.

* **Build 272** (2015-06-27)
- Protected images and their thumbnails are now supported in the back-end.
Expand Down
12 changes: 12 additions & 0 deletions config/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,16 @@

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

/*
|--------------------------------------------------------------------------
| Cross Site Request Forgery (CSRF) Protection
|--------------------------------------------------------------------------
|
| If the CSRF protection is enabled, all "postback" requests are checked
| for a valid security token.
|
*/

'enableCsrfProtection' => false,

];
17 changes: 9 additions & 8 deletions modules/backend/classes/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use View;
use Flash;
use Event;
use Config;
use Request;
use Backend;
use Session;
Expand Down Expand Up @@ -34,9 +35,9 @@
*/
class Controller extends Extendable
{
use \System\Traits\ViewMaker;
use \System\Traits\AssetMaker;
use \System\Traits\ConfigMaker;
use \System\Traits\ViewMaker;
use \Backend\Traits\WidgetMaker;
use \October\Rain\Support\Traits\Emitter;

Expand Down Expand Up @@ -118,11 +119,6 @@ class Controller extends Extendable
*/
protected $statusCode = 200;

/**
* @var bool Determine if submission requests use CSRF protection.
*/
public $useSecurityToken = true;

/**
* Constructor.
*/
Expand Down Expand Up @@ -176,7 +172,7 @@ public function run($action = null, $params = [])
/*
* Check security token.
*/
if ($this->useSecurityToken && !$this->verifyCsrfToken()) {
if (!$this->verifyCsrfToken()) {
return Response::make(Lang::get('backend::lang.page.invalid_token.label'), 403);
}

Expand Down Expand Up @@ -629,11 +625,16 @@ public function isBackendHintHidden($name)

/**
* Checks the request data / headers for a valid CSRF token.
* Returns false if a valid token is not found.
* Returns false if a valid token is not found. Override this
* method to disable the check.
* @return bool
*/
protected function verifyCsrfToken()
{
if (!Config::get('cms.enableCsrfProtection')) {
return true;
}

if (in_array(Request::method(), ['HEAD', 'GET', 'OPTIONS'])) {
return true;
}
Expand Down

0 comments on commit 6068921

Please sign in to comment.