Skip to content

Commit

Permalink
Disallow direct controller names
Browse files Browse the repository at this point in the history
Controller names with the default routing should not allow direct
plugin, or fully qualified namespace names.
  • Loading branch information
markstory committed Aug 11, 2015
1 parent b86dcd6 commit 67d1c98
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Routing/Filter/ControllerFactoryFilter.php
Expand Up @@ -73,6 +73,9 @@ protected function _getController($request, $response)
);
$namespace .= '/' . implode('/', $prefixes);
}
if (strpos($controller, '\\') !== false || strpos($controller, '.') !== false) {
return false;
}
$className = false;
if ($pluginPath . $controller) {
$className = App::classname($pluginPath . $controller, $namespace, 'Controller');
Expand Down
49 changes: 48 additions & 1 deletion tests/TestCase/Routing/DispatcherTest.php
Expand Up @@ -23,7 +23,6 @@
use Cake\Network\Session;
use Cake\Routing\Dispatcher;
use Cake\Routing\Filter\ControllerFactoryFilter;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
use Cake\Utility\Inflector;

Expand Down Expand Up @@ -409,6 +408,54 @@ public function testPrefixDispatchPlugin()
);
}

/**
* test forbidden controller names.
*
* @expectedException \Cake\Routing\Exception\MissingControllerException
* @expectedExceptionMessage Controller class TestPlugin.Tests could not be found.
* @return void
*/
public function testDispatchBadPluginName()
{
Plugin::load('TestPlugin');

$request = new Request([
'url' => 'TestPlugin.Tests/index',
'params' => [
'plugin' => '',
'controller' => 'TestPlugin.Tests',
'action' => 'index',
'pass' => [],
'return' => 1
]
]);
$response = $this->getMock('Cake\Network\Response');
$this->dispatcher->dispatch($request, $response);
}

/**
* test forbidden controller names.
*
* @expectedException \Cake\Routing\Exception\MissingControllerException
* @expectedExceptionMessage Controller class TestApp\Controller\PostsController could not be found.
* @return void
*/
public function testDispatchBadName()
{
$request = new Request([
'url' => 'TestApp%5CController%5CPostsController/index',
'params' => [
'plugin' => '',
'controller' => 'TestApp\Controller\PostsController',
'action' => 'index',
'pass' => [],
'return' => 1
]
]);
$response = $this->getMock('Cake\Network\Response');
$this->dispatcher->dispatch($request, $response);
}

/**
* Test dispatcher filters being called.
*
Expand Down

0 comments on commit 67d1c98

Please sign in to comment.