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

Logged-Out-User & Routes Issue ( UF ver 4.6.6 ) #8

Closed
jonsq opened this issue Mar 21, 2023 · 7 comments
Closed

Logged-Out-User & Routes Issue ( UF ver 4.6.6 ) #8

jonsq opened this issue Mar 21, 2023 · 7 comments

Comments

@jonsq
Copy link

jonsq commented Mar 21, 2023

*Note: I'm not sure if this affects previous versions of UF.

If you are not signed in and you try to access the settings page, a "ForbiddenException" is thrown and an error is displayed.

I feel the better solution here is to redirect the user to the sign in page.

To do this, simply edit the routes file "routes\ConfigManager.php" so that the group declaration ends with ->add('authGuard')

Example of the modified code:

$app->group('/settings', function () {
    $this->get('', 'UserFrosting\Sprinkle\ConfigManager\Controller\ConfigManagerController:displayMain')
         ->setName('ConfigManager');

    $this->post('/{schema}', 'UserFrosting\Sprinkle\ConfigManager\Controller\ConfigManagerController:update')
         ->setName('ConfigManager.save');
})->add('authGuard');
@lcharette
Copy link
Owner

if (!$authorizer->checkAccess($currentUser, 'update_site_config')) {
throw new ForbiddenException();
}

It's a design choice. Forbidden exception will be shown for any logged in user that don't have the update_site_config permission.

Any "guest" user (aka non logged in) won't have this permission, so it does make sense to add authGuard as no guest user can access this page. However, any guest redirected to the login page will be redirected to the setting page upon login. If this (logged in) user don't have permission, they will be still be shown the Forbidden exception... I'm not closed to the idea of adding authGuard in a Pull Request, but at the same time don't think it's 100% useful. This page is supposed to be "known" for admin only, not everyday users. Either way, it would be even more secure to not acknowledge it exist if user don't have permission to access it maybe ?

@jonsq
Copy link
Author

jonsq commented Mar 22, 2023

You make several good points. Honestly I'm not certain what the best choice would be for the majority of users.

I found this purely by accident when I had a tab opened to the settings page overnight and the next morning (when my login had expired), I refreshed the settings page tab and saw an error page that did not reference any sort of Forbidden Exception (Screenshot shown below).

It took me a while to figure out what was wrong. Ended up temporarily modifing the filp/whoops PlainTextHandler.php file to fix it's error, (Screenshot shown below), so that I could see the true problem of Forbidden access.

UF_ConfigManager_Error

@lcharette
Copy link
Owner

That error should be fixed by updating composer. It was a bug in flip/whoops

@jonsq
Copy link
Author

jonsq commented Mar 23, 2023

I was running composer version 2.5.4 when I installed this Sprinkle. That was the latest version available at the time. Is there something I may have missed or done wrong?

@jonsq
Copy link
Author

jonsq commented Mar 23, 2023

I see that the whoops bug you're referring to was fixed in whoops release version 2.15.1, which is included with UF 4.6.6.

However, reading up on that whoops bug pointed me in the right direction.

UF 4.6.6's "core" sprinkle has the same bug in "app\sprinkles\core\src\Error\Renderer\WhoopsRenderer.php". This file is missing the setRun(..) statement after line # 295 (example of missing statement shown below).

$plainTextHandler->setRun($this->getRun());

I don't see any mention of this problem on UF's GitHub. Perhaps it takes a very specific scenario to raise this bug and not enough users have ran into it yet?

@lcharette
Copy link
Owner

I see how this could indeed be an issue on UF4 code. A PR would be welcomed.

@jonsq
Copy link
Author

jonsq commented Mar 27, 2023

I would if I thought I could. However I don't see any usage of the whoops' "RunInterface" in UF's code and I honestly wouldn't know where to begin to implement it.

For the time being, I'm satisfied with the add('authGuard') "solution" I provided in my original comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants