Browse Source

Merge pull request #750 from tigrang/security-component-enhancement

Added `disabledActions` feature to SecurityComponent
José Lorenzo Rodríguez 13 years ago
parent
commit
1ff63758ad

+ 10 - 5
lib/Cake/Controller/Component/SecurityComponent.php

@@ -130,6 +130,13 @@ class SecurityComponent extends Component {
 	public $unlockedFields = array();
 
 /**
+ * Actions to exclude from any security checks
+ *
+ * @var array
+ */
+	public $unlockedActions = array();
+
+/**
  * Whether to validate POST data.  Set to false to disable for data coming from 3rd party
  * services, etc.
  *
@@ -218,13 +225,11 @@ class SecurityComponent extends Component {
 			$controller->request->params['requested'] != 1
 		);
 
-		if ($isPost && $isNotRequestAction && $this->validatePost) {
-			if ($this->_validatePost($controller) === false) {
+		if (!in_array($this->_action, (array)$this->unlockedActions) && $isPost && $isNotRequestAction) {
+			if ($this->validatePost && $this->_validatePost($controller) === false) {
 				return $this->blackHole($controller, 'auth');
 			}
-		}
-		if ($isPost && $isNotRequestAction && $this->csrfCheck) {
-			if ($this->_validateCsrf($controller) === false) {
+			if ($this->csrfCheck && $this->_validateCsrf($controller) === false) {
 				return $this->blackHole($controller, 'csrf');
 			}
 		}

+ 14 - 0
lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php

@@ -1372,4 +1372,18 @@ class SecurityComponentTest extends CakeTestCase {
 		$this->assertTrue(isset($result['4']));
 		$this->assertTrue(isset($result['5']));
 	}
+
+/**
+ * Test unlocked actions
+ *
+ * @return void
+ */
+	public function testUnlockedActions() {
+		$_SERVER['REQUEST_METHOD'] = 'POST';
+		$this->Controller->request->data = array('data');
+		$this->Controller->Security->unlockedActions = 'index';
+		$this->Controller->Security->blackHoleCallback = null;
+		$result = $this->Controller->Security->startup($this->Controller);
+		$this->assertNull($result);
+	}
 }