Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move logic to prevent access to initController #5648

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions system/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
* the LICENSE file that was distributed with this source code.
*/

use CodeIgniter\Exceptions\PageNotFoundException;

/*
* System URI Routing
*
Expand All @@ -21,11 +19,6 @@
* already loaded up and ready for us to use.
*/

// Prevent access to initController method
$routes->add('(:any)/initController', static function () {
throw PageNotFoundException::forPageNotFound();
});

// Migrations
$routes->cli('migrations/(:segment)/(:segment)', '\CodeIgniter\Commands\MigrationsCommand::$1/$2');
$routes->cli('migrations/(:segment)', '\CodeIgniter\Commands\MigrationsCommand::$1');
Expand Down
5 changes: 5 additions & 0 deletions system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ public function autoRoute(string $uri)
$this->method = array_shift($segments) ?: $this->method;
}

// Prevent access to initController method
if (strtolower($this->method) === 'initcontroller') {
throw PageNotFoundException::forPageNotFound();
}

if (! empty($segments)) {
$this->params = $segments;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/system/Router/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@ public function testAutoRouteRejectsMidDot()
$router->autoRoute('Foo.bar');
}

public function testAutoRouteRejectsInitController()
{
$router = new Router($this->collection, $this->request);
$router->setTranslateURIDashes(true);

$this->expectException(PageNotFoundException::class);

$router->autoRoute('home/initController');
}

public function testDetectsLocales()
{
$router = new Router($this->collection, $this->request);
Expand Down