diff --git a/src/Controller/Component/SecurityComponent.php b/src/Controller/Component/SecurityComponent.php index 390c32a2d74..9af68375917 100644 --- a/src/Controller/Component/SecurityComponent.php +++ b/src/Controller/Component/SecurityComponent.php @@ -289,7 +289,7 @@ protected function _validatePost(Controller $controller) { if (strpos($token, ':')) { list($token, $locked) = explode(':', $token, 2); } - unset($check['_Token']); + unset($check['_Token'], $check['_csrfToken']); $locked = explode('|', $locked); $unlocked = explode('|', $unlocked); diff --git a/tests/TestCase/Controller/Component/SecurityComponentTest.php b/tests/TestCase/Controller/Component/SecurityComponentTest.php index 4806e12e90c..5997b8d64fa 100644 --- a/tests/TestCase/Controller/Component/SecurityComponentTest.php +++ b/tests/TestCase/Controller/Component/SecurityComponentTest.php @@ -426,6 +426,26 @@ public function testValidatePostObjectDeserialize() { $this->assertFalse($result, 'validatePost passed when key was missing. %s'); } +/** + * Tests validation post data ignores `_csrfToken`. + * + * @return void + */ + public function testValidatePostIgnoresCsrfToken() { + $event = new Event('Controller.startup', $this->Controller); + $this->Controller->Security->startup($event); + + $fields = '8e26ef05379e5402c2c619f37ee91152333a0264%3A'; + $unlocked = ''; + + $this->Controller->request->data = array( + '_csrfToken' => 'abc123', + 'Model' => array('multi_field' => array('1', '3')), + '_Token' => compact('fields', 'unlocked') + ); + $this->assertTrue($this->Controller->Security->validatePost($this->Controller)); + } + /** * Tests validation of checkbox arrays *