From 554805197766b5f90d711e233706a92634f84536 Mon Sep 17 00:00:00 2001 From: Ahammar Yassine Date: Tue, 4 Dec 2018 16:03:16 +0100 Subject: [PATCH 1/3] Ask confirmation when is run as admin --- src/Composer/Console/Application.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index e6ff7da9d..9478561fb 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -207,6 +207,12 @@ class Application extends BaseApplication if (function_exists('posix_getuid') && posix_getuid() === 0) { if ($commandName !== 'self-update' && $commandName !== 'selfupdate') { $io->writeError('Do not run Composer as root/super user! See https://getcomposer.org/root for details'); + + if ($io->isInteractive()) { + if (!$io->askConfirmation('Continue as root/super user [yes]? ', true)) { + exit(0); + } + } } if ($uid = (int) getenv('SUDO_UID')) { // Silently clobber any sudo credentials on the invoking user to avoid privilege escalations later on From 0fd4ef6d8eaa29d887704d0fcc0eaf2b302dddbe Mon Sep 17 00:00:00 2001 From: Ahammar Yassine Date: Tue, 4 Dec 2018 17:47:45 +0100 Subject: [PATCH 2/3] Ask confirmation when is run as admin Use return instead of exit for the Application to run cleanly --- src/Composer/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 9478561fb..c148c73fa 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -210,7 +210,7 @@ class Application extends BaseApplication if ($io->isInteractive()) { if (!$io->askConfirmation('Continue as root/super user [yes]? ', true)) { - exit(0); + return 0; } } } From b4fae00db24cc08ad5d5c3b5e2dec8c6156d5d39 Mon Sep 17 00:00:00 2001 From: Ahammar Yassine Date: Tue, 4 Dec 2018 18:54:57 +0100 Subject: [PATCH 3/3] Change return code to 1 --- src/Composer/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index c148c73fa..3398cef69 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -210,7 +210,7 @@ class Application extends BaseApplication if ($io->isInteractive()) { if (!$io->askConfirmation('Continue as root/super user [yes]? ', true)) { - return 0; + return 1; } } }