diff --git a/etc/config/command.php b/etc/config/command.php index 047af324a..7b45a2595 100644 --- a/etc/config/command.php +++ b/etc/config/command.php @@ -11,9 +11,9 @@ $magentoObjectManager = $magentoObjectManagerFactory->create($_SERVER); $tokenModel = $magentoObjectManager->get(\Magento\Integration\Model\Oauth\Token::class); - $tokenPassedIn = urldecode($_POST['token']); - $command = urldecode($_POST['command']); - $arguments = urldecode($_POST['arguments']); + $tokenPassedIn = urldecode($_POST['token'] ?? ''); + $command = urldecode($_POST['command'] ?? ''); + $arguments = urldecode($_POST['arguments'] ?? ''); // Token returned will be null if the token we passed in is invalid $tokenFromMagento = $tokenModel->loadByToken($tokenPassedIn)->getToken(); @@ -22,7 +22,8 @@ $magentoBinary = $php . ' -f ../../../../bin/magento'; $valid = validateCommand($magentoBinary, $command); if ($valid) { - $process = new Symfony\Component\Process\Process($magentoBinary . " $command" . " $arguments"); + $fullCommand = escapeshellcmd($magentoBinary . " $command" . " $arguments"); + $process = new Symfony\Component\Process\Process($fullCommand); $process->setIdleTimeout(60); $process->setTimeout(0); $idleTimeout = false; @@ -40,6 +41,11 @@ $output = "CLI command timed out, no output available."; $idleTimeout = true; } + + if (checkForFilePath($output)) { + $output = "CLI output suppressed, filepath detected in output."; + } + $exitCode = $process->getExitCode(); if ($exitCode == 0 || $idleTimeout) { @@ -103,3 +109,13 @@ function trimAfterWhitespace($string) { return strtok($string, ' '); } + +/** + * Detects file path in string. + * @param string $string + * @return boolean + */ +function checkForFilePath($string) +{ + return preg_match('/\/[\S]+\//', $string); +}