Skip to content

Commit

Permalink
Merge branch '2.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jan 5, 2022
2 parents b96c419 + c2cdc3e commit 3a27cb2
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/Composer/Util/ProcessExecutor.php
Expand Up @@ -102,18 +102,7 @@ public function executeTty($command, $cwd = null)
*/
private function doExecute($command, $cwd, $tty, &$output = null)
{
if ($this->io && $this->io->isDebug()) {
$safeCommand = Preg::replaceCallback('{://(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)@}i', function ($m) {
// if the username looks like a long (12char+) hex string, or a modern github token (e.g. ghp_xxx) we obfuscate that
if (Preg::isMatch('{^([a-f0-9]{12,}|gh[a-z]_[a-zA-Z0-9_]+)$}', $m['user'])) {
return '://***:***@';
}

return '://'.$m['user'].':***@';
}, $command);
$safeCommand = Preg::replace("{--password (.*[^\\\\]\') }", '--password \'***\' ', $safeCommand);
$this->io->writeError('Executing command ('.($cwd ?: 'CWD').'): '.$safeCommand);
}
$this->outputCommandRun($command, $cwd, false);

$this->captureOutput = func_num_args() > 3;
$this->errorOutput = '';
Expand Down Expand Up @@ -230,17 +219,7 @@ private function startJob($id)
$command = $job['command'];
$cwd = $job['cwd'];

if ($this->io && $this->io->isDebug()) {
$safeCommand = Preg::replaceCallback('{://(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)@}i', function ($m) {
if (Preg::isMatch('{^[a-f0-9]{12,}$}', $m['user'])) {
return '://***:***@';
}

return '://'.$m['user'].':***@';
}, $command);
$safeCommand = Preg::replace("{--password (.*[^\\\\]\') }", '--password \'***\' ', $safeCommand);
$this->io->writeError('Executing async command ('.($cwd ?: 'CWD').'): '.$safeCommand);
}
$this->outputCommandRun($command, $cwd, true);

try {
$process = Process::fromShellCommandline($command, $cwd, null, null, static::getTimeout());
Expand Down Expand Up @@ -407,6 +386,33 @@ public static function escape($argument)
return self::escapeArgument($argument);
}

/**
* @param string $command
* @param ?string $cwd
* @param bool $async
* @return void
*/
private function outputCommandRun($command, $cwd, $async)
{
if (null === $this->io || !$this->io->isDebug()) {
return;
}

$safeCommand = Preg::replaceCallback('{://(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)@}i', function ($m) {
// if the username looks like a long (12char+) hex string, or a modern github token (e.g. ghp_xxx) we obfuscate that
if (Preg::isMatch('{^([a-f0-9]{12,}|gh[a-z]_[a-zA-Z0-9_]+)$}', $m['user'])) {
return '://***:***@';
}
if (Preg::isMatch('{^[a-f0-9]{12,}$}', $m['user'])) {
return '://***:***@';
}

return '://'.$m['user'].':***@';
}, $command);
$safeCommand = Preg::replace("{--password (.*[^\\\\]\') }", '--password \'***\' ', $safeCommand);
$this->io->writeError('Executing'.($async ? ' async' : '').' command ('.($cwd ?: 'CWD').'): '.$safeCommand);
}

/**
* Escapes a string to be used as a shell argument for Symfony Process.
*
Expand Down

0 comments on commit 3a27cb2

Please sign in to comment.