Skip to content
Merged
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
24 changes: 6 additions & 18 deletions lib/private/AppFramework/DependencyInjection/DIContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,28 +308,12 @@ public function has($id): bool {
* @param list<class-string> $chain
*/
#[\Override]
protected function query(string $name, bool $autoload = true, array $chain = []): mixed {
protected function query(string $name, bool $autoload = true, array $chain = [], bool $fallback = true): mixed {
$name = $this->resolveAlias($name);
if ($name === 'AppName' || $name === 'appName') {
return $this->appName;
}

$result = $this->queryNoFallback($name, $chain);
if ($result !== null) {
return $result;
}
return $this->server->query($name, $autoload, $chain);
}

/**
* @param string already sanitized $name
* @param list<class-string> $chain
* @return mixed
* @throws QueryException if the query could not be resolved
* @internal
*/
public function queryNoFallback($name, array $chain) {
$name = $this->resolveAlias($name);
if (isset($this->container[$name])) {
return $this->container[$name];
} elseif ($this->appName === 'settings' && str_starts_with($name, 'OC\\Settings\\')) {
Expand All @@ -343,6 +327,10 @@ public function queryNoFallback($name, array $chain) {
/* AppFramework services are scoped to the application */
return parent::query($name, chain: $chain);
}
return null;
if ($fallback) {
return $this->server->query($name, $autoload, $chain);
} else {
throw new QueryException('Could not resolve ' . $name . '! Class can not be instantiated', 1);
}
}
}
13 changes: 3 additions & 10 deletions lib/private/ServerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
$applicationClassName = $sensitiveNamespace . '\\AppInfo\\Application';
if (class_exists($applicationClassName)) {
/* The application constructor will register the container, see App::__construct */
$app = new $applicationClassName();

Check failure on line 90 in lib/private/ServerContainer.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-security

TaintedCallable

lib/private/ServerContainer.php:90:17: TaintedCallable: Detected tainted text (see https://psalm.dev/243)
if (isset($this->appContainers[$namespace])) {
$this->appContainers[$namespace]->setInInternalContainer($applicationClassName, $app);
/** @psalm-suppress NoValue false-positive (see comment above) */
Expand Down Expand Up @@ -124,16 +124,9 @@
#[\Override]
protected function query(string $name, bool $autoload = true, array $chain = []): mixed {
$name = $this->resolveAlias($name);
if (str_starts_with($name, 'OCA\\')) {
// In case the service starts with OCA\ we try to find the service in the apps container.
if (($appContainer = $this->getAppContainerForService($name)) !== null) {
$result = $appContainer->queryNoFallback($name, $chain);
if ($result !== null) {
return $result;
}
throw new QueryException('Could not resolve ' . $name . '!'
. ' Class can not be instantiated', 1);
}
// In case the service starts with OCA\ we try to find the service in the apps container.
if (($appContainer = $this->getAppContainerForService($name)) !== null) {
return $appContainer->query($name, $autoload, $chain, fallback:false);
}

return parent::query($name, $autoload, $chain);
Expand Down
Loading