Fix caching routes by users with an active session#56921
Merged
provokateurin merged 3 commits intomasterfrom Dec 15, 2025
Merged
Fix caching routes by users with an active session#56921provokateurin merged 3 commits intomasterfrom
provokateurin merged 3 commits intomasterfrom
Conversation
Member
Author
|
/backport to stable32 |
74ea8f5 to
860bdfd
Compare
Member
|
Is this still needed after #56926 ? |
Member
|
Yes the other PR was just a quick fix for the release. We still need to enable caching again and probably with this PR. @danxuliu can you rebase and revert my commit? |
provokateurin
requested changes
Dec 12, 2025
Member
provokateurin
left a comment
There was a problem hiding this comment.
LGTM and also thanks for adding a test!
860bdfd to
a20a797
Compare
provokateurin
approved these changes
Dec 12, 2025
This reverts commit 90948f5. It temporary disabled cache for routes until an actual fix was added, which is done in the following commits. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
When a user has an active session only the apps that are enabled for the user are initially loaded. In order to cache the routes the routes for all apps are loaded, but routes defined in routes.php are taken into account only if the app was already loaded. Therefore, when the routes were cached in a request by a user with an active session only the routes for apps enabled for that user were cached, and those routes were used by any other user, independently of which apps they had access to. To solve that now all the enabled apps are explicitly loaded before caching the routes. Note that this did not affect routes defined using annotations on the controller files; in that case the loaded routes do not depend on the previously loaded apps, as it explicitly checks all the enabled apps. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
a20a797 to
51ed61b
Compare
Member
Author
|
Rebased again to fix the DCO in the revert commit. |
come-nc
approved these changes
Dec 15, 2025
Contributor
|
I’m still wondering whether we should just load all enabled apps (for any user) even for users for which the application is not enabled. The whole feature about enabling only for some users is a bit weird. |
| } | ||
| parent::loadRoutes(); | ||
| $cachedRoutes = $this->serializeRouteCollection($this->root); | ||
| $this->cache->set($key, $cachedRoutes, ($this->config->getSystemValueBool('debug') ? 3 : 3600)); |
Member
There was a problem hiding this comment.
Are we sure debug is false in this test, otherwise the 3s can be ran over between the requests and the cache already expired
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #56789, which is a regression introduced in #52793
When a user has an active session only the apps that are enabled for the user are initially loaded*. In order to cache the routes the routes for all apps are loaded, but routes defined in routes.php are taken into account only if the app was already loaded. Therefore, when the routes were cached in a request by a user with an active session only the routes for apps enabled for that user were cached, and those routes were used by any other user, independently of which apps they had access to. To solve that now all the enabled apps are explicitly loaded before caching the routes.
Note that this did not affect routes defined using annotations on the controller files; in that case the loaded routes do not depend on the previously loaded apps, as it explicitly checks all the enabled apps.
*As soon as the session is initialized, which happens when loading base.php, the legacy
OC_APP::getEnabledAppswill return only the apps enabled for the user. That method is used byAppManager::loadApps, so once the session is initialized any load of (several) apps will be restricted to those enabled for the user (explicitly loading a single app still works as expected). Therefore, when$appManager->loadApps()is called from the OCS handler or from the index.php handler (throughhandleRequestin base.php) only the apps for the user are loaded.Steps to reproduce
'memcache.local' => '\\OC\\Memcache\\APCu', to config.php) if not enabled alreadyweather_statusapp only for a specific group (for simplicity admin is used here)Clear the APCu cache (call
apcu_clear_cache()somehow, for example using https://github.com/krakjoe/apcu/blob/master/apc.php or the helper apps/testing/clean_apcu_cache.php added in this pull request; restarting the web server would reset the APCu cache, but it might also kill the user session and make the test invalid)In the same Bash terminal as before, do a request with the logged in user, for example:
weather_statusapp by a user member of the group that it is enabled for (again for simplicity admin is used here):Result with this pull request
The query succeeded
Result without this pull request
Invalid query returned; if the APCu cache is cleared again and the request repeated then it will now succeed (as the routes will be regenerated by the admin, which has access to the app)