mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge pull request #1850 from MGatner/secure-routable-controller-methods
Secure routable controller methods
This commit is contained in:
commit
b5c3f1839b
@ -57,3 +57,9 @@ $routes->cli('migrations', '\CodeIgniter\Commands\MigrationsCommand::index');
|
||||
|
||||
// CLI Catchall - uses a _remap to call Commands
|
||||
$routes->cli('ci(:any)', '\CodeIgniter\CLI\CommandRunner::index/$1');
|
||||
|
||||
// Prevent access to initController method
|
||||
$routes->add('(:any)/initController', function()
|
||||
{
|
||||
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
||||
});
|
||||
|
@ -138,7 +138,7 @@ class Controller
|
||||
*
|
||||
* @throws \CodeIgniter\HTTP\Exceptions\HTTPException
|
||||
*/
|
||||
public function forceHTTPS(int $duration = 31536000)
|
||||
protected function forceHTTPS(int $duration = 31536000)
|
||||
{
|
||||
force_https($duration, $this->request, $this->response);
|
||||
}
|
||||
@ -151,7 +151,7 @@ class Controller
|
||||
*
|
||||
* @param integer $time
|
||||
*/
|
||||
public function cachePage(int $time)
|
||||
protected function cachePage(int $time)
|
||||
{
|
||||
CodeIgniter::cache($time);
|
||||
}
|
||||
@ -185,7 +185,7 @@ class Controller
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function validate($rules, array $messages = []): bool
|
||||
protected function validate($rules, array $messages = []): bool
|
||||
{
|
||||
$this->validator = Services::validation();
|
||||
|
||||
|
@ -87,7 +87,8 @@ class ControllerTest extends \CIUnitTestCase
|
||||
$this->controller = new Controller();
|
||||
$this->controller->initController($this->request, $this->response, $this->logger);
|
||||
|
||||
$this->assertNull($this->controller->cachePage(10));
|
||||
$method = $this->getPrivateMethodInvoker($this->controller, 'cachePage');
|
||||
$this->assertNull($method(10));
|
||||
}
|
||||
|
||||
public function testValidate()
|
||||
@ -97,7 +98,8 @@ class ControllerTest extends \CIUnitTestCase
|
||||
$this->controller->initController($this->request, $this->response, $this->logger);
|
||||
|
||||
// and that we can attempt validation, with no rules
|
||||
$this->assertFalse($this->controller->validate([]));
|
||||
$method = $this->getPrivateMethodInvoker($this->controller, 'validate');
|
||||
$this->assertFalse($method([]));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user