Skip to content

Commit 4a59f29

Browse files
committed
MQE-1510
1 parent f895b71 commit 4a59f29

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

etc/config/command.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
$magentoObjectManager = $magentoObjectManagerFactory->create($_SERVER);
1212
$tokenModel = $magentoObjectManager->get(\Magento\Integration\Model\Oauth\Token::class);
1313

14-
$tokenPassedIn = urldecode($_POST['token']);
15-
$command = urldecode($_POST['command']);
16-
$arguments = urldecode($_POST['arguments']);
14+
$tokenPassedIn = urldecode($_POST['token'] ?? '');
15+
$command = urldecode($_POST['command'] ?? '');
16+
$arguments = urldecode($_POST['arguments'] ?? '');
1717

1818
// Token returned will be null if the token we passed in is invalid
1919
$tokenFromMagento = $tokenModel->loadByToken($tokenPassedIn)->getToken();
@@ -22,8 +22,14 @@
2222
$magentoBinary = $php . ' -f ../../../../bin/magento';
2323
$valid = validateCommand($magentoBinary, $command);
2424
if ($valid) {
25-
$fullCommand = escapeshellcmd($magentoBinary . " $command" . " $arguments");
26-
$process = new Symfony\Component\Process\Process($fullCommand);
25+
$fullCommand = $magentoBinary . " $command" . " $arguments";
26+
$escapedCommand = escapeshellcmd($fullCommand);
27+
if ($fullCommand !== $escapedCommand) {
28+
http_response_code(403);
29+
echo("Unsafe characters detected, command was not executed.");
30+
return;
31+
}
32+
$process = new Symfony\Component\Process\Process($escapedCommand);
2733
$process->setIdleTimeout(60);
2834
$process->setTimeout(0);
2935
$idleTimeout = false;

0 commit comments

Comments
 (0)