Skip to content

Commit c0fb45e

Browse files
MarkusBauerMarkus Bauer
andauthored
Fix potential CSRF circumvention with custom HTTP methods (kamilwylegala#76)
* Backported patch, fixing potential CSRF circumvention with custom HTTP methods. Upstream: cakephp/cakephp@0f818a2 * Fix unit tests for SecurityComponent --------- Co-authored-by: Markus Bauer <markus.bauer@cispa.saarland>
1 parent b918df8 commit c0fb45e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/Cake/Controller/Component/SecurityComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class SecurityComponent extends Component {
227227
public function startup(Controller $controller) {
228228
$this->request = $controller->request;
229229
$this->_action = $controller->request->params['action'];
230-
$hasData = ($controller->request->data || $controller->request->is(array('put', 'post', 'delete', 'patch')));
230+
$hasData = ($controller->request->data || !$controller->request->is(['head', 'get', 'options']));
231231
try {
232232
$this->_methodsRequired($controller);
233233
$this->_secureRequired($controller);

lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class SecurityComponentTest extends CakeTestCase {
162162
*/
163163
public function setUp() : void {
164164
parent::setUp();
165+
$_SERVER['REQUEST_METHOD'] = 'GET';
165166

166167
$request = $this->getMock('CakeRequest', array('here'), array('posts/index', false));
167168
$request->addParams(array('controller' => 'posts', 'action' => 'index'));
@@ -321,7 +322,7 @@ public function testRequireSecureFail() {
321322
* @return void
322323
*/
323324
public function testRequireSecureSucceed() {
324-
$_SERVER['REQUEST_METHOD'] = 'Secure';
325+
$_SERVER['REQUEST_METHOD'] = 'GET';
325326
$this->Controller->request['action'] = 'posted';
326327
$_SERVER['HTTPS'] = 'on';
327328
$this->Controller->Security->requireSecure('posted');

0 commit comments

Comments
 (0)