You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The unauthorized user is redirected from the CP to the referrer. But that doesn't make sense if the user is coming from an external site and in the case of OAuth authentication, a redirect loop can be created. IMO the user should see an error message explaining what happened.
See Statamic\Exceptions\Concerns\RendersControlPanelExceptions::getAuthExceptionRedirectUrl(). There is the comment:
If we came to this URL from another, we'll send them back, but not if it was the login page otherwise there'd be a redirect loop.
and if:
if ($referrer && $referrer != cp_route('login')) {
return$referrer;
}
So there is solved the risk of redirect loop only for default login via email and password, not for OAuth authentication.
There should be something like this:
// If we came to this URL from another, we'll send them back, but not// if it was an external site or the login page otherwise there'd be a redirect loop.if ($referrer && str_starts_with($referrer, url('/')) && $referrer != cp_route('login')) {
return$referrer;
}
How to reproduce
1. Create an unauthorized user
In statamic application create unauthorized user (superadmin = false, no role).
If you are not able to create the OAuth authentication, try this simulator. On a domain other than the statamic application, create a script with this simple code:
If you use the OAuth simulator above, you must login to CP manually (real OAuth will do it itself). Login to CP via email and password as the unauthorized user. You will be redirected to the unauthorized page /cp/auth/unauthorized as expected.
4. Sign in via OAuth
Sign in to OAuth or simulate it with the OAuth simulator (submit the form or click on the link). You will be redirected to the control panel of your statamic application, but you will be immediately redirected back to an external site because you have no permissions.
Bug description
The unauthorized user is redirected from the CP to the referrer. But that doesn't make sense if the user is coming from an external site and in the case of OAuth authentication, a redirect loop can be created. IMO the user should see an error message explaining what happened.
See
Statamic\Exceptions\Concerns\RendersControlPanelExceptions::getAuthExceptionRedirectUrl()
. There is the comment:and
if
:So there is solved the risk of redirect loop only for default login via email and password, not for OAuth authentication.
There should be something like this:
How to reproduce
1. Create an unauthorized user
In statamic application create unauthorized user (superadmin = false, no role).
2. OAuth authentication
Create an OAuth authentication according to the doc https://statamic.dev/oauth.
If you are not able to create the OAuth authentication, try this simulator. On a domain other than the statamic application, create a script with this simple code:
or with simpler code:
3. Login to CP via email
If you use the OAuth simulator above, you must login to CP manually (real OAuth will do it itself). Login to CP via email and password as the unauthorized user. You will be redirected to the unauthorized page
/cp/auth/unauthorized
as expected.4. Sign in via OAuth
Sign in to OAuth or simulate it with the OAuth simulator (submit the form or click on the link). You will be redirected to the control panel of your statamic application, but you will be immediately redirected back to an external site because you have no permissions.
Because the OAuth authentication automatically creates unauthorized users this always happened if the user doesn't exists.
Logs
No response
Environment
Installation
Fresh statamic/statamic site via CLI
Additional details
No response
The text was updated successfully, but these errors were encountered: