Description
PHP warnings are being logged repeatedly when the catchall route handles
GET requests that are not the main application page.
Environment
- Nextcloud: 33
- Workspace: 4.4.0
- PHP: PHP 8.4.20
- Web server: Apache
- OS: AlmaLinux
Warnings in log
Undefined array key "userSession" at apps/workspace/templates/index.php#28
Undefined array key "addedGroupDisabled" at apps/workspace/templates/index.php#27
Undefined array key "aclInheritPerUser" at apps/workspace/templates/index.php#26
Root cause
The catchall route defined in appinfo/routes.php:
[
'name' => 'page#index',
'url' => '/{path}',
'verb' => 'GET',
'requirements' => ['path' => '.*'],
'defaults' => ['path' => 'dummy'],
'postfix' => 'catchall',
]
This route captures all GET requests — including API calls and asset
requests — and passes them through PageController::index(), which
renders the templates/index.php template.
In some of these requests, $this->session->getUser() returns null
(unauthenticated or background requests), so the template receives null
instead of the expected values for userSession, aclInheritPerUser
and addedGroupDisabled, triggering PHP undefined array key warnings.
Expected behavior
No PHP warnings should be logged during normal application usage.
Either the catchall route should check for a valid session before
rendering the template, or the template should handle missing/null
values gracefully using the null coalescing operator ??.
Suggested fix
In PageController::index(), guard against null session:
'userSession' => $this->session->getUser()?->getUID() ?? '',
Or in templates/index.php, use null-safe access:
<input type="hidden" id="userSession"
value="<?php p($_['userSession'] ?? ''); ?>">
<input type="hidden" id="aclInheritPerUser"
value="<?php p(($_['aclInheritPerUser'] ?? false) ? 'true': 'false'); ?>">
<input type="hidden" id="addedGroupDisabled"
value="<?php p(($_['addedGroupDisabled'] ?? false) ? 'true': 'false'); ?>">
Description
PHP warnings are being logged repeatedly when the catchall route handles
GET requests that are not the main application page.
Environment
Warnings in log
Undefined array key "userSession" at apps/workspace/templates/index.php#28
Undefined array key "addedGroupDisabled" at apps/workspace/templates/index.php#27
Undefined array key "aclInheritPerUser" at apps/workspace/templates/index.php#26
Root cause
The catchall route defined in
appinfo/routes.php:[ 'name' => 'page#index', 'url' => '/{path}', 'verb' => 'GET', 'requirements' => ['path' => '.*'], 'defaults' => ['path' => 'dummy'], 'postfix' => 'catchall', ]This route captures all GET requests — including API calls and asset
requests — and passes them through
PageController::index(), whichrenders the
templates/index.phptemplate.In some of these requests,
$this->session->getUser()returnsnull(unauthenticated or background requests), so the template receives
nullinstead of the expected values for
userSession,aclInheritPerUserand
addedGroupDisabled, triggering PHP undefined array key warnings.Expected behavior
No PHP warnings should be logged during normal application usage.
Either the catchall route should check for a valid session before
rendering the template, or the template should handle missing/null
values gracefully using the null coalescing operator
??.Suggested fix
In
PageController::index(), guard against null session:Or in
templates/index.php, use null-safe access: