Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 49 additions & 32 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
}
}

localhost {
franken.local {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be pushed I guess

php_server {
# Keeps /index.php out of Nextcloud's generated URLs, matching the pretty-URL rewrite below.
env front_controller_active true

worker {
file index.php
num 32
Expand Down Expand Up @@ -42,40 +45,54 @@ localhost {

encode gzip

redir /.well-known/carddav /remote.php/dav 301
redir /.well-known/caldav /remote.php/dav 301
# Wrapped in route{} so these all run in the order written, regardless of Caddy's
# default directive ordering: the specific rewrites and the forbidden-path block
# must be evaluated before the catch-all pretty-URL rewrite below.
route {
redir /.well-known/carddav /remote.php/dav 301
redir /.well-known/caldav /remote.php/dav 301

# Rule: Maps most RFC 8615 compliant well-known URIs to our main frontend controller (/index.php) by default
@wellKnown {
path "/.well-known/"
not {
path /.well-known/acme-challenge
path /.well-known/pki-validation
# Rule: Maps most RFC 8615 compliant well-known URIs to our main frontend controller (/index.php) by default
@wellKnown {
path "/.well-known/"
not {
path /.well-known/acme-challenge
path /.well-known/pki-validation
}
}
}
rewrite @wellKnown /index.php
rewrite @wellKnown /index.php

rewrite /ocm-provider/ /index.php
rewrite /ocm-provider/ /index.php

@forbidden {
path /.htaccess
path /data/*
path /config/*
path /db_structure
path /.xml
path /README
path /3rdparty/*
path /lib/*
path /templates/*
path /occ
path /build
path /tests
path /console.php
path /autotest
path /issue
path /indi
path /db_
path /console
@forbidden {
path /.htaccess
path /data/*
path /config/*
path /db_structure
path /.xml
path /README
path /3rdparty/*
path /lib/*
path /templates/*
path /occ
path /build
path /tests
path /console.php
path /autotest
path /issue
path /indi
path /db_
path /console
}
respond @forbidden 404

# Pretty URLs: rewrite anything that isn't already destined for a worker's own
# prefix and doesn't correspond to an existing static file (assets, etc.) to the
# front controller, so franken.local/ works instead of only franken.local/index.php/.
@prettyUrl {
not path /index.php/* /remote.php/* /ocs/v1.php/* /ocs/v2.php/*
not file
}
rewrite @prettyUrl /index.php{path}
}
respond @forbidden 404
}
4 changes: 0 additions & 4 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Test\TestCase;

Expand All @@ -48,7 +47,6 @@
*/
#[\PHPUnit\Framework\Attributes\Group('RoutingWeirdness')]
class ViewControllerTest extends TestCase {
private ContainerInterface&MockObject $container;
private IAppManager&MockObject $appManager;
private IAppConfig&MockObject $appConfig;
private ICacheFactory&MockObject $cacheFactory;
Expand Down Expand Up @@ -113,13 +111,11 @@ protected function setUp(): void {
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->eventLogger = $this->createMock(IEventLogger::class);
$this->container = $this->createMock(ContainerInterface::class);
$this->router = new Router(
$this->logger,
$this->request,
$this->config,
$this->eventLogger,
$this->container,
$this->appManager,
);

Expand Down
5 changes: 5 additions & 0 deletions core/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OC\Core\Listener\BeforeTemplateRenderedListener;
use OC\Core\Listener\LoadAdditionalEntriesListener;
use OC\Core\Listener\PasswordUpdatedListener;
use OC\Core\Listener\PersistentServiceInvalidationListener;
use OC\Core\Listener\RestrictInteractionListener;
use OC\Core\Notification\CoreNotifier;
use OC\Core\Sharing\Permission\EditSharePermissionPreset;
Expand All @@ -42,6 +43,8 @@
use OC\DirectEditing\Listeners\UserDisabledTokenCleanupListener as UserDisabledDirectEditingTokenCleanupListener;
use OC\OCM\OCMDiscoveryHandler;
use OC\TagManager;
use OCP\App\Events\AppDisableEvent;
use OCP\App\Events\AppEnableEvent;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
Expand Down Expand Up @@ -92,6 +95,8 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
$context->registerEventListener(BeforeLoginTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
$context->registerEventListener(LoadAdditionalEntriesEvent::class, LoadAdditionalEntriesListener::class);
$context->registerEventListener(AppEnableEvent::class, PersistentServiceInvalidationListener::class);
$context->registerEventListener(AppDisableEvent::class, PersistentServiceInvalidationListener::class);
$context->registerEventListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
$context->registerEventListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
$context->registerEventListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
Expand Down
34 changes: 34 additions & 0 deletions core/Listener/PersistentServiceInvalidationListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\Core\Listener;

use OCP\App\Events\AppDisableEvent;
use OCP\App\Events\AppEnableEvent;
use OCP\AppFramework\Utility\IPersistentServiceInvalidator;
use OCP\AppFramework\Utility\PersistentServiceGroup;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<AppEnableEvent|AppDisableEvent>
*/
class PersistentServiceInvalidationListener implements IEventListener {
public function __construct(
private IPersistentServiceInvalidator $invalidator,
) {
}

#[\Override]
public function handle(Event $event): void {
if ($event instanceof AppEnableEvent || $event instanceof AppDisableEvent) {
$this->invalidator->invalidate(PersistentServiceGroup::Apps);
}
}
}
7 changes: 7 additions & 0 deletions lib/OC.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

use OC\AppFramework\Utility\SimpleContainer;
use OC\Files\Filesystem;
use OC\NavigationManager;
use OC\Profiler\BuiltInProfiler;
Expand Down Expand Up @@ -780,6 +781,10 @@ public static function initForRequest(): void {
$config = Server::get(IConfig::class);
$request = Server::get(IRequest::class);

// The router may be reused from a previous request on a long-running worker; the
// request-derived context it builds itself with must always reflect the request being served.
Server::get(\OC\Route\Router::class)->refreshContext($request);

try {
$profiler = new BuiltInProfiler(
$config,
Expand Down Expand Up @@ -1382,6 +1387,8 @@ private static function resetStaticProperties(): void {
*/
public static function handleRequests(callable $handler): void {
if (function_exists('frankenphp_handle_request') && isset($_SERVER['FRANKENPHP_WORKER']) && $_SERVER['FRANKENPHP_WORKER'] === '1') {
SimpleContainer::$keepPersistentServices = true;

$maxRequests = (int)($_SERVER['MAX_REQUESTS'] ?? 0);
for ($nbRequests = 0; !$maxRequests || $nbRequests < $maxRequests; ++$nbRequests) {
$keepRunning = \frankenphp_handle_request($handler);
Expand Down
5 changes: 5 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
'OCP\\AppFramework\\Attribute\\ExceptionalImplementable' => $baseDir . '/lib/public/AppFramework/Attribute/ExceptionalImplementable.php',
'OCP\\AppFramework\\Attribute\\Implementable' => $baseDir . '/lib/public/AppFramework/Attribute/Implementable.php',
'OCP\\AppFramework\\Attribute\\Listenable' => $baseDir . '/lib/public/AppFramework/Attribute/Listenable.php',
'OCP\\AppFramework\\Attribute\\PersistAcrossRequests' => $baseDir . '/lib/public/AppFramework/Attribute/PersistAcrossRequests.php',
'OCP\\AppFramework\\Attribute\\Throwable' => $baseDir . '/lib/public/AppFramework/Attribute/Throwable.php',
'OCP\\AppFramework\\AuthPublicShareController' => $baseDir . '/lib/public/AppFramework/AuthPublicShareController.php',
'OCP\\AppFramework\\Bootstrap\\IBootContext' => $baseDir . '/lib/public/AppFramework/Bootstrap/IBootContext.php',
Expand Down Expand Up @@ -198,7 +199,9 @@
'OCP\\AppFramework\\Services\\IInitialState' => $baseDir . '/lib/public/AppFramework/Services/IInitialState.php',
'OCP\\AppFramework\\Services\\InitialStateProvider' => $baseDir . '/lib/public/AppFramework/Services/InitialStateProvider.php',
'OCP\\AppFramework\\Utility\\IControllerMethodReflector' => $baseDir . '/lib/public/AppFramework/Utility/IControllerMethodReflector.php',
'OCP\\AppFramework\\Utility\\IPersistentServiceInvalidator' => $baseDir . '/lib/public/AppFramework/Utility/IPersistentServiceInvalidator.php',
'OCP\\AppFramework\\Utility\\ITimeFactory' => $baseDir . '/lib/public/AppFramework/Utility/ITimeFactory.php',
'OCP\\AppFramework\\Utility\\PersistentServiceGroup' => $baseDir . '/lib/public/AppFramework/Utility/PersistentServiceGroup.php',
'OCP\\App\\AppInfoDefinition' => $baseDir . '/lib/public/App/AppInfoDefinition.php',
'OCP\\App\\AppPathNotFoundException' => $baseDir . '/lib/public/App/AppPathNotFoundException.php',
'OCP\\App\\Events\\AppDisableEvent' => $baseDir . '/lib/public/App/Events/AppDisableEvent.php',
Expand Down Expand Up @@ -1250,6 +1253,7 @@
'OC\\AppFramework\\Services\\AppConfig' => $baseDir . '/lib/private/AppFramework/Services/AppConfig.php',
'OC\\AppFramework\\Services\\InitialState' => $baseDir . '/lib/private/AppFramework/Services/InitialState.php',
'OC\\AppFramework\\Utility\\ControllerMethodReflector' => $baseDir . '/lib/private/AppFramework/Utility/ControllerMethodReflector.php',
'OC\\AppFramework\\Utility\\PersistentServiceInvalidator' => $baseDir . '/lib/private/AppFramework/Utility/PersistentServiceInvalidator.php',
'OC\\AppFramework\\Utility\\QueryNotFoundException' => $baseDir . '/lib/private/AppFramework/Utility/QueryNotFoundException.php',
'OC\\AppFramework\\Utility\\SimpleContainer' => $baseDir . '/lib/private/AppFramework/Utility/SimpleContainer.php',
'OC\\AppFramework\\Utility\\TimeFactory' => $baseDir . '/lib/private/AppFramework/Utility/TimeFactory.php',
Expand Down Expand Up @@ -1638,6 +1642,7 @@
'OC\\Core\\Listener\\FeedBackHandler' => $baseDir . '/core/Listener/FeedBackHandler.php',
'OC\\Core\\Listener\\LoadAdditionalEntriesListener' => $baseDir . '/core/Listener/LoadAdditionalEntriesListener.php',
'OC\\Core\\Listener\\PasswordUpdatedListener' => $baseDir . '/core/Listener/PasswordUpdatedListener.php',
'OC\\Core\\Listener\\PersistentServiceInvalidationListener' => $baseDir . '/core/Listener/PersistentServiceInvalidationListener.php',
'OC\\Core\\Listener\\RestrictInteractionListener' => $baseDir . '/core/Listener/RestrictInteractionListener.php',
'OC\\Core\\Middleware\\TwoFactorMiddleware' => $baseDir . '/core/Middleware/TwoFactorMiddleware.php',
'OC\\Core\\Migrations\\Version13000Date20170705121758' => $baseDir . '/core/Migrations/Version13000Date20170705121758.php',
Expand Down
5 changes: 5 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\AppFramework\\Attribute\\ExceptionalImplementable' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Attribute/ExceptionalImplementable.php',
'OCP\\AppFramework\\Attribute\\Implementable' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Attribute/Implementable.php',
'OCP\\AppFramework\\Attribute\\Listenable' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Attribute/Listenable.php',
'OCP\\AppFramework\\Attribute\\PersistAcrossRequests' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Attribute/PersistAcrossRequests.php',
'OCP\\AppFramework\\Attribute\\Throwable' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Attribute/Throwable.php',
'OCP\\AppFramework\\AuthPublicShareController' => __DIR__ . '/../../..' . '/lib/public/AppFramework/AuthPublicShareController.php',
'OCP\\AppFramework\\Bootstrap\\IBootContext' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Bootstrap/IBootContext.php',
Expand Down Expand Up @@ -239,7 +240,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\AppFramework\\Services\\IInitialState' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Services/IInitialState.php',
'OCP\\AppFramework\\Services\\InitialStateProvider' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Services/InitialStateProvider.php',
'OCP\\AppFramework\\Utility\\IControllerMethodReflector' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/IControllerMethodReflector.php',
'OCP\\AppFramework\\Utility\\IPersistentServiceInvalidator' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/IPersistentServiceInvalidator.php',
'OCP\\AppFramework\\Utility\\ITimeFactory' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/ITimeFactory.php',
'OCP\\AppFramework\\Utility\\PersistentServiceGroup' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/PersistentServiceGroup.php',
'OCP\\App\\AppInfoDefinition' => __DIR__ . '/../../..' . '/lib/public/App/AppInfoDefinition.php',
'OCP\\App\\AppPathNotFoundException' => __DIR__ . '/../../..' . '/lib/public/App/AppPathNotFoundException.php',
'OCP\\App\\Events\\AppDisableEvent' => __DIR__ . '/../../..' . '/lib/public/App/Events/AppDisableEvent.php',
Expand Down Expand Up @@ -1291,6 +1294,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\AppFramework\\Services\\AppConfig' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Services/AppConfig.php',
'OC\\AppFramework\\Services\\InitialState' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Services/InitialState.php',
'OC\\AppFramework\\Utility\\ControllerMethodReflector' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/ControllerMethodReflector.php',
'OC\\AppFramework\\Utility\\PersistentServiceInvalidator' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/PersistentServiceInvalidator.php',
'OC\\AppFramework\\Utility\\QueryNotFoundException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/QueryNotFoundException.php',
'OC\\AppFramework\\Utility\\SimpleContainer' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/SimpleContainer.php',
'OC\\AppFramework\\Utility\\TimeFactory' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/TimeFactory.php',
Expand Down Expand Up @@ -1679,6 +1683,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Listener\\FeedBackHandler' => __DIR__ . '/../../..' . '/core/Listener/FeedBackHandler.php',
'OC\\Core\\Listener\\LoadAdditionalEntriesListener' => __DIR__ . '/../../..' . '/core/Listener/LoadAdditionalEntriesListener.php',
'OC\\Core\\Listener\\PasswordUpdatedListener' => __DIR__ . '/../../..' . '/core/Listener/PasswordUpdatedListener.php',
'OC\\Core\\Listener\\PersistentServiceInvalidationListener' => __DIR__ . '/../../..' . '/core/Listener/PersistentServiceInvalidationListener.php',
'OC\\Core\\Listener\\RestrictInteractionListener' => __DIR__ . '/../../..' . '/core/Listener/RestrictInteractionListener.php',
'OC\\Core\\Middleware\\TwoFactorMiddleware' => __DIR__ . '/../../..' . '/core/Middleware/TwoFactorMiddleware.php',
'OC\\Core\\Migrations\\Version13000Date20170705121758' => __DIR__ . '/../../..' . '/core/Migrations/Version13000Date20170705121758.php',
Expand Down
16 changes: 16 additions & 0 deletions lib/private/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use OC\Config\ConfigManager;
use OC\Config\PresetManager;
use OC\Memcache\Factory as CacheFactory;
use OCP\AppFramework\Attribute\PersistAcrossRequests;
use OCP\AppFramework\Utility\IPersistentServiceInvalidator;
use OCP\AppFramework\Utility\PersistentServiceGroup;
use OCP\Config\Lexicon\Entry;
use OCP\Config\Lexicon\Strictness;
use OCP\Config\ValueType;
Expand Down Expand Up @@ -51,6 +54,7 @@
* @since 7.0.0
* @since 29.0.0 - Supporting types and lazy loading
*/
#[PersistAcrossRequests(invalidatedBy: [PersistentServiceGroup::Config, PersistentServiceGroup::Apps])]
class AppConfig implements IAppConfig {
private const int APP_MAX_LENGTH = 32;
private const int KEY_MAX_LENGTH = 64;
Expand Down Expand Up @@ -951,6 +955,7 @@ private function setTypedValue(

if ($refreshCache) {
$this->clearCache();
$this->invalidatePersistedServices();
return true;
}

Expand All @@ -962,10 +967,19 @@ private function setTypedValue(
}
$this->valueTypes[$app][$key] = $type;
$this->clearLocalCache();
$this->invalidatePersistedServices();

return true;
}

/**
* Discards services kept alive across requests (see {@see \OCP\AppFramework\Attribute\PersistAcrossRequests})
* that declared a dependency on {@see PersistentServiceGroup::Config}.
*/
private function invalidatePersistedServices(): void {
Server::get(IPersistentServiceInvalidator::class)->invalidate(PersistentServiceGroup::Config);
}

/**
* Change the type of config value.
*
Expand Down Expand Up @@ -1273,6 +1287,7 @@ public function deleteKey(string $app, string $key): void {
unset($this->fastCache[$app][$key]);
unset($this->valueTypes[$app][$key]);
$this->clearLocalCache();
$this->invalidatePersistedServices();
}

/**
Expand All @@ -1291,6 +1306,7 @@ public function deleteApp(string $app): void {
$qb->executeStatement();

$this->clearCache();
$this->invalidatePersistedServices();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ private function getUserId(): string {
*/
#[\Override]
public function registerCapability($serviceName) {
$this->query(CapabilitiesManager::class)->registerCapability(function () use ($serviceName) {
return $this->query($serviceName);
});
$this->get(CapabilitiesManager::class)->registerCapability(function () use ($serviceName) {
return $this->get($serviceName);
}, $serviceName);
}

#[\Override]
Expand Down
Loading
Loading