BUGFIX: disallow numeric actions - numeric array indexes are incorrectly picked up as allowed actions (#5331) (from r103092)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112118 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-13 03:30:54 +00:00
parent 6f30671604
commit eef3ff8021
2 changed files with 9 additions and 3 deletions

View File

@ -216,10 +216,15 @@ class RequestHandler extends ViewableData {
$action = strtolower($action);
$actions = $this->allowedActions();
// Check if the action is defined in the allowed actions as either a
// key or value. Note that if the action is numeric, then keys are not
// searched for actions to prevent actual array keys being recognised
// as actions.
if(is_array($actions)) {
if(array_key_exists($action, $actions) || in_array($action, $actions)) {
return true;
}
$isKey = !is_numeric($action) && array_key_exists($action, $actions);
$isValue = in_array($action, $actions);
if($isKey || $isValue) return true;
}
if(!is_array($actions) || !$this->uninherited('allowed_actions')) {

View File

@ -110,6 +110,7 @@ class ControllerTest extends FunctionalTest {
public function testHasAction() {
$controller = new ControllerTest_HasAction();
$this->assertFalse($controller->hasAction('1'), 'Numeric actions do not slip through.');
$this->assertFalse($controller->hasAction('undefined'), 'undefined actions do not exist');
$this->assertTrue($controller->hasAction('allowed_action'), 'allowed actions are recognised');
$this->assertTrue($controller->hasAction('template_action'), 'action-specific templates are recognised');