Skip to content

Commit

Permalink
Fix potential CSRF circumvention with custom HTTP methods (#76)
Browse files Browse the repository at this point in the history
* Backported patch, fixing potential CSRF circumvention with custom HTTP methods.

Upstream: cakephp/cakephp@0f818a2

* Fix unit tests for SecurityComponent

---------

Co-authored-by: Markus Bauer <[email protected]>
  • Loading branch information
MarkusBauer and Markus Bauer authored Jul 24, 2024
1 parent b918df8 commit c0fb45e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/SecurityComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class SecurityComponent extends Component {
public function startup(Controller $controller) {
$this->request = $controller->request;
$this->_action = $controller->request->params['action'];
$hasData = ($controller->request->data || $controller->request->is(array('put', 'post', 'delete', 'patch')));
$hasData = ($controller->request->data || !$controller->request->is(['head', 'get', 'options']));
try {
$this->_methodsRequired($controller);
$this->_secureRequired($controller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class SecurityComponentTest extends CakeTestCase {
*/
public function setUp() : void {
parent::setUp();
$_SERVER['REQUEST_METHOD'] = 'GET';

$request = $this->getMock('CakeRequest', array('here'), array('posts/index', false));
$request->addParams(array('controller' => 'posts', 'action' => 'index'));
Expand Down Expand Up @@ -321,7 +322,7 @@ public function testRequireSecureFail() {
* @return void
*/
public function testRequireSecureSucceed() {
$_SERVER['REQUEST_METHOD'] = 'Secure';
$_SERVER['REQUEST_METHOD'] = 'GET';
$this->Controller->request['action'] = 'posted';
$_SERVER['HTTPS'] = 'on';
$this->Controller->Security->requireSecure('posted');
Expand Down

0 comments on commit c0fb45e

Please sign in to comment.