ci-phpunit-test icon indicating copy to clipboard operation
ci-phpunit-test copied to clipboard

pre_controller can modify $class / $method

Open xalagu opened this issue 3 years ago • 2 comments

in codeigniter pre_controller methods modifying global $class $method variables can modify the route

code in codeigniter\framework\system\core\CodeIgniter.php

$EXT->call_hook('pre_controller');
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
$CI = new $class();

with this fix, this behavior will work in testing also

xalagu avatar May 13 '22 07:05 xalagu

Can you show a minimum sample code to modify $class $method variables ? Or please send a PR to https://github.com/kenjis/ci-app-for-ci-phpunit-test

kenjis avatar May 13 '22 08:05 kenjis

function pre_controller_hook_verify_permissions() {
  if( not_have_permission() ){
	$GLOBALS['class'] = 'MY_auth_access_denied'; //new controller
	$GLOBALS['method'] = 'index'; //new method
  }
}

xalagu avatar May 13 '22 09:05 xalagu

Thank you for sending this PR. I released as v3.0.4.

kenjis avatar Dec 26 '22 04:12 kenjis