1
0
Fork 0

Output more warnings about plugins being disabled to hint that it may cause problems, fixes #11839 (#11842)

pull/11844/head
Jordi Boggiano 2024-02-09 11:56:25 +01:00 committed by GitHub
parent 33335fdfdd
commit 690fe716c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 4 deletions

View File

@ -220,7 +220,7 @@ class Application extends BaseApplication
// Clobber sudo credentials if COMPOSER_ALLOW_SUPERUSER is not set before loading plugins // Clobber sudo credentials if COMPOSER_ALLOW_SUPERUSER is not set before loading plugins
if ($needsSudoCheck) { if ($needsSudoCheck) {
$isNonAllowedRoot = function_exists('posix_getuid') && posix_getuid() === 0; $isNonAllowedRoot = $this->isRunningAsRoot();
if ($isNonAllowedRoot) { if ($isNonAllowedRoot) {
if ($uid = (int) Platform::getEnv('SUDO_UID')) { if ($uid = (int) Platform::getEnv('SUDO_UID')) {
@ -476,6 +476,12 @@ class Application extends BaseApplication
$io->writeError('<error>Check https://getcomposer.org/doc/06-config.md#process-timeout for details</error>', true, IOInterface::QUIET); $io->writeError('<error>Check https://getcomposer.org/doc/06-config.md#process-timeout for details</error>', true, IOInterface::QUIET);
} }
if ($this->getDisablePluginsByDefault() && $this->isRunningAsRoot() && !$this->io->isInteractive()) {
$io->writeError('<error>Plugins have been disabled automatically as you are running as root, this may be the cause of the following exception. See also https://getcomposer.org/root</error>', true, IOInterface::QUIET);
} elseif ($exception instanceof CommandNotFoundException && $this->getDisablePluginsByDefault()) {
$io->writeError('<error>Plugins have been disabled, which may be why some commands are missing, unless you made a typo</error>', true, IOInterface::QUIET);
}
$hints = HttpDownloader::getExceptionHints($exception); $hints = HttpDownloader::getExceptionHints($exception);
if (null !== $hints && count($hints) > 0) { if (null !== $hints && count($hints) > 0) {
foreach ($hints as $hint) { foreach ($hints as $hint) {
@ -678,4 +684,9 @@ class Application extends BaseApplication
return $config->get('use-parent-dir'); return $config->get('use-parent-dir');
} }
private function isRunningAsRoot(): bool
{
return function_exists('posix_getuid') && posix_getuid() === 0;
}
} }

View File

@ -94,8 +94,8 @@ class InstallationManager
/** /**
* Disables plugins. * Disables plugins.
* *
* We prevent any plugins from being instantiated by simply * We prevent any plugins from being instantiated by
* deactivating the installer for them. This ensure that no third-party * disabling the PluginManager. This ensures that no third-party
* code is ever executed. * code is ever executed.
*/ */
public function disablePlugins(): void public function disablePlugins(): void
@ -105,7 +105,7 @@ class InstallationManager
continue; continue;
} }
unset($this->installers[$i]); $installer->disablePlugins();
} }
} }

View File

@ -43,6 +43,11 @@ class PluginInstaller extends LibraryInstaller
return $packageType === 'composer-plugin' || $packageType === 'composer-installer'; return $packageType === 'composer-plugin' || $packageType === 'composer-installer';
} }
public function disablePlugins(): void
{
$this->getPluginManager()->disablePlugins();
}
/** /**
* @inheritDoc * @inheritDoc
*/ */

View File

@ -153,6 +153,7 @@ class PluginManager
public function registerPackage(PackageInterface $package, bool $failOnMissingClasses = false, bool $isGlobalPlugin = false): void public function registerPackage(PackageInterface $package, bool $failOnMissingClasses = false, bool $isGlobalPlugin = false): void
{ {
if ($this->arePluginsDisabled($isGlobalPlugin ? 'global' : 'local')) { if ($this->arePluginsDisabled($isGlobalPlugin ? 'global' : 'local')) {
$this->io->writeError('<warning>The "'.$package->getName().'" plugin was not loaded as plugins are disabled.</warning>');
return; return;
} }
@ -656,6 +657,14 @@ class PluginManager
return $this->disablePlugins === true || $this->disablePlugins === $type; return $this->disablePlugins === true || $this->disablePlugins === $type;
} }
/**
* @internal
*/
public function disablePlugins(): void
{
$this->disablePlugins = true;
}
/** /**
* @internal * @internal
*/ */