2222 * @package OCA\Guests
2323 */
2424class AppWhitelist {
25- private string $ baseUrl ;
26- private int $ baseUrlLength ;
25+ private readonly string $ baseUrl ;
26+ private readonly int $ baseUrlLength ;
2727
2828 public const WHITELIST_ALWAYS = ',core,theming,settings,avatar,files,heartbeat,dav,guests,impersonate,accessibility,terms_of_service,dashboard,weather_status,user_status,apporder,twofactor_totp,twofactor_webauthn,twofactor_backupcodes,twofactor_nextcloud_notification ' ;
2929
3030 public const DEFAULT_WHITELIST = 'files_trashbin,files_versions,files_sharing,files_texteditor,text,activity,firstrunwizard,photos,notifications,dashboard,user_status,weather_status ' ;
3131
3232 /**
3333 * AppWhitelist constructor.
34- *
35- * @param Config $config
36- * @param GuestManager $guestManager
37- * @param IL10N $l10n
38- * @param IAppManager $appManager
39- * @param IURLGenerator $urlGenerator
40- * @param LoggerInterface $logger
4134 */
4235 public function __construct (
4336 IURLGenerator $ urlGenerator ,
44- private Config $ config ,
45- private GuestManager $ guestManager ,
46- private IL10N $ l10n ,
47- private IAppManager $ appManager ,
48- private LoggerInterface $ logger ,
37+ private readonly Config $ config ,
38+ private readonly GuestManager $ guestManager ,
39+ private readonly IL10N $ l10n ,
40+ private readonly IAppManager $ appManager ,
41+ private readonly LoggerInterface $ logger ,
4942 ) {
5043 $ this ->baseUrl = $ urlGenerator ->getBaseUrl ();
5144 $ this ->baseUrlLength = strlen ($ this ->baseUrl );
@@ -62,9 +55,6 @@ public function isWhitelistEnabled(): bool {
6255 return $ this ->config ->useWhitelist ();
6356 }
6457
65- /**
66- * @param false|string $url
67- */
6858 public function isUrlAllowed (IUser $ user , string |false $ url ): bool {
6959 if ($ this ->guestManager ->isGuest ($ user ) && $ this ->isWhitelistEnabled ()) {
7060 $ app = $ this ->getRequestedApp ($ url );
@@ -98,45 +88,43 @@ public function verifyAccess(IUser $user, IRequest $request): void {
9888 /**
9989 * Core has \OC::$REQUESTEDAPP but it isn't set until the routes are matched
10090 * taken from \OC\Route\Router::match()
101- *
102- * @param false|string $url
10391 */
10492 private function getRequestedApp (string |false $ url ): string {
10593 if (substr ($ url , 0 , $ this ->baseUrlLength ) === $ this ->baseUrl ) {
10694 $ url = substr ($ url , $ this ->baseUrlLength );
10795 }
108- if (strpos ($ url , '/index.php/ ' ) === 0 ) {
96+ if (str_starts_with ($ url , '/index.php/ ' )) {
10997 $ url = substr ($ url , 10 );
11098 }
111- if (substr ($ url , 0 , 6 ) === '/apps/ ' ) {
99+ if (str_starts_with ($ url , '/apps/ ' ) ) {
112100 // empty string / 'apps' / $app / rest of the route
113101 [, , $ app ,] = explode ('/ ' , $ url , 4 );
114102 return \OC_App::cleanAppId ($ app );
115103 } elseif ($ url === '/cron.php ' ) {
116104 return 'core ' ;
117- } elseif (substr ($ url , 0 , 6 ) === '/core/ ' ) {
105+ } elseif (str_starts_with ($ url , '/core/ ' ) ) {
118106 return 'core ' ;
119- } elseif (substr ($ url , 0 , 4 ) === '/js/ ' ) {
107+ } elseif (str_starts_with ($ url , '/js/ ' ) ) {
120108 return 'core ' ;
121- } elseif (substr ($ url , 0 , 5 ) === '/css/ ' ) {
109+ } elseif (str_starts_with ($ url , '/css/ ' ) ) {
122110 return 'core ' ;
123- } elseif (substr ($ url , 0 , 6 ) === '/login ' ) {
111+ } elseif (str_starts_with ($ url , '/login ' ) ) {
124112 return 'core ' ;
125- } elseif (substr ($ url , 0 , 7 ) === '/logout ' ) {
113+ } elseif (str_starts_with ($ url , '/logout ' ) ) {
126114 return 'core ' ;
127- } elseif (substr ($ url , 0 , 3 ) === '/f/ ' ) {
115+ } elseif (str_starts_with ($ url , '/f/ ' ) ) {
128116 return 'files ' ;
129- } elseif (substr ($ url , 0 , 8 ) === '/webdav/ ' ) {
117+ } elseif (str_starts_with ($ url , '/webdav/ ' ) ) {
130118 return 'dav ' ;
131- } elseif (substr ($ url , 0 , 5 ) === '/dav/ ' ) {
119+ } elseif (str_starts_with ($ url , '/dav/ ' ) ) {
132120 return 'dav ' ;
133- } elseif (substr ($ url , 0 , 6 ) === '/call/ ' ) {
121+ } elseif (str_starts_with ($ url , '/call/ ' ) ) {
134122 return 'spreed ' ;
135- } elseif (substr ($ url , 0 , 10 ) === '/settings/ ' ) {
123+ } elseif (str_starts_with ($ url , '/settings/ ' ) ) {
136124 return 'settings ' ;
137- } elseif (substr ($ url , 0 , 8 ) === '/avatar/ ' ) {
125+ } elseif (str_starts_with ($ url , '/avatar/ ' ) ) {
138126 return 'avatar ' ;
139- } elseif (substr ($ url , 0 , 10 ) === '/heartbeat ' ) {
127+ } elseif (str_starts_with ($ url , '/heartbeat ' ) ) {
140128 return 'heartbeat ' ;
141129 }
142130 return 'core ' ;
0 commit comments