Skip to content

Commit

Permalink
Fix cyclic redirects algorithm #798
Browse files Browse the repository at this point in the history
  • Loading branch information
jorikfon committed Sep 23, 2024
1 parent 334f413 commit 94b2ba0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/AdminCabinet/Plugins/NotFoundPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public function beforeException(
]
);

return false;
case DispatcherException::EXCEPTION_CYCLIC_ROUTING:
$dispatcher->forward(
[
'controller' => 'errors',
'action' => 'show500',
]
);
return false;
}
}
Expand Down
14 changes: 2 additions & 12 deletions src/AdminCabinet/Plugins/SecurityPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,6 @@ private function redirectToHome(Dispatcher $dispatcher): void{
$homePath='/admin-cabinet/extensions/index';
}

$currentPageCacheKey = 'redirectCount'.md5($homePath);
$redirectCount = $this->session->get($currentPageCacheKey)??0;
$redirectCount++;
$this->session->set($currentPageCacheKey, $redirectCount);
if ($redirectCount > 5){
$this->session->set($currentPageCacheKey, 0);
$this->forwardTo401Error($dispatcher);
return;
}

// Extract the module, controller, and action from the home page path
$module = explode('/', $homePath)[1];
$controller = explode('/', $homePath)[2];
Expand Down Expand Up @@ -155,7 +145,7 @@ private function redirectToHome(Dispatcher $dispatcher): void{
* Redirects the user to a 401 error page.
* @param $dispatcher Dispatcher instance for handling the redirection.
*/
private function forwardTo401Error($dispatcher): void{
private function forwardTo401Error(Dispatcher $dispatcher): void{
$dispatcher->forward([
'module' => 'admin-cabinet',
'controller' => 'errors',
Expand All @@ -168,7 +158,7 @@ private function forwardTo401Error($dispatcher): void{
* Redirects the user to the login page.
* @param $dispatcher Dispatcher instance for handling the redirection.
*/
private function forwardToLoginPage($dispatcher): void{
private function forwardToLoginPage(Dispatcher $dispatcher): void{
$dispatcher->forward([
'controller' => 'session',
'action' => 'index',
Expand Down

0 comments on commit 94b2ba0

Please sign in to comment.