Skip to content

Commit

Permalink
feat: gracefully handle command not found exception - avoid creds exp…
Browse files Browse the repository at this point in the history
…osure (#54406)

* gracefully handle command not found exception to avoid exposure of credentials

* Update DbCommand.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
chinmaypurav and taylorotwell authored Jan 30, 2025
1 parent 01571b3 commit 62044a5
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Illuminate/Database/Console/DbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Illuminate\Support\ConfigurationUrlParser;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use UnexpectedValueException;

Expand Down Expand Up @@ -44,13 +45,21 @@ public function handle()
return Command::FAILURE;
}

(new Process(
array_merge([$this->getCommand($connection)], $this->commandArguments($connection)),
null,
$this->commandEnvironment($connection)
))->setTimeout(null)->setTty(true)->mustRun(function ($type, $buffer) {
$this->output->write($buffer);
});
try {
(new Process(
array_merge([$command = $this->getCommand($connection)], $this->commandArguments($connection)),
null,
$this->commandEnvironment($connection)
))->setTimeout(null)->setTty(true)->mustRun(function ($type, $buffer) {
$this->output->write($buffer);
});
} catch (ProcessFailedException $e) {
throw_unless($e->getProcess()->getExitCode() === 127, $e);

$this->error("{$command} not found in path.");

return Command::FAILURE;
}

return 0;
}
Expand Down

0 comments on commit 62044a5

Please sign in to comment.