Skip to content

Commit

Permalink
[Runtime] Negate register_argc_argv when its On
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 6, 2024
1 parent 46fd79d commit 2c35056
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions SymfonyRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ public function __construct(array $options = [])
$envKey = $options['env_var_name'] ??= 'APP_ENV';
$debugKey = $options['debug_var_name'] ??= 'APP_DEBUG';

if (isset($_SERVER['argv']) && !empty($_GET)) {
// register_argc_argv=On is too risky in web servers
$_SERVER['argv'] = [];
$_SERVER['argc'] = 0;
}

if (isset($options['env'])) {
$_SERVER[$envKey] = $options['env'];
} elseif (empty($_GET) && isset($_SERVER['argv']) && class_exists(ArgvInput::class)) {
Expand Down Expand Up @@ -203,10 +209,6 @@ protected static function register(GenericRuntime $runtime): GenericRuntime

private function getInput(): ArgvInput
{
if (!empty($_GET) && filter_var(ini_get('register_argc_argv'), \FILTER_VALIDATE_BOOL)) {
throw new \Exception('CLI applications cannot be run safely on non-CLI SAPIs with register_argc_argv=On.');
}

if (isset($this->input)) {
return $this->input;
}
Expand Down

0 comments on commit 2c35056

Please sign in to comment.