Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue: Missing CSRF protection
Dev Can now be enabled in LSYii_Application.php. Its currently deactivated as it is mostly untested. Dev New HttpRequest class enables exceptions for certain POST requests (like AJAX)
- Loading branch information
Showing
6 changed files
with
81 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/* | ||
* LimeSurvey | ||
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz | ||
* All rights reserved. | ||
* License: GNU/GPL License v2 or later, see LICENSE.php | ||
* LimeSurvey is free software. This version may have been modified pursuant | ||
* to the GNU General Public License, and as distributed it includes or | ||
* is derivative of works licensed under the GNU General Public License or | ||
* other free or open source software licenses. | ||
* See COPYRIGHT.php for copyright notices and details. | ||
*/ | ||
|
||
|
||
/** | ||
* Description of HttpRequest | ||
* | ||
* | ||
* Used in LSYii_Application.php | ||
* <pre> | ||
* 'request'=>array( | ||
* 'class'=>'HttpRequest', | ||
* 'noCsrfValidationRoutes'=>array( | ||
* '^services/wsdl.*$' | ||
* ), | ||
* 'enableCsrfValidation'=>true, | ||
* 'enableCookieValidation'=>true, | ||
* ), | ||
* </pre> | ||
* | ||
* Every route will be interpreted as a regex pattern. | ||
* | ||
*/ | ||
class HttpRequest extends CHttpRequest { | ||
public $noCsrfValidationRoutes = array(); | ||
|
||
protected function normalizeRequest(){ | ||
parent::normalizeRequest(); | ||
|
||
if($_SERVER['REQUEST_METHOD'] != 'POST') return; | ||
|
||
$route = Yii::app()->getUrlManager()->parseUrl($this); | ||
if($this->enableCsrfValidation){ | ||
foreach($this->noCsrfValidationRoutes as $cr){ | ||
if(preg_match('#'.$cr.'#', $route)){ | ||
Yii::app()->detachEventHandler('onBeginRequest', | ||
array($this,'validateCsrfToken')); | ||
Yii::trace('Route "'.$route.' passed without CSRF validation'); | ||
break; // found first route and break | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters