Skip to content

Commit 2f57eaf

Browse files
committed
minor symfony#58785 [Runtime] Negate register_argc_argv when On (nicolas-grekas)
This PR was merged into the 7.2 branch. Discussion ---------- [Runtime] Negate `register_argc_argv` when `On` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT The `register_argc_argv` ini setting is a terrible idea from the past that can have dramatic consequences: https://symfony.com/blog/cve-2024-50340-ability-to-change-environment-from-query While Symfony itself will ignore argv injected via GET, apps are still at risk. With this PR, I propose to harden all Symfony apps by always emptying argv/argc, so that their value cannot be hijacked. There are no legitimate use case for this setting anyway. Linking to php/php-src#12344 for cross-reference. Commits ------- 917b064 [Runtime] Negate register_argc_argv when its On
2 parents d8f8080 + 917b064 commit 2f57eaf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Symfony/Component/Runtime/SymfonyRuntime.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ public function __construct(array $options = [])
9393
$envKey = $options['env_var_name'] ??= 'APP_ENV';
9494
$debugKey = $options['debug_var_name'] ??= 'APP_DEBUG';
9595

96+
if (isset($_SERVER['argv']) && !empty($_GET)) {
97+
// register_argc_argv=On is too risky in web servers
98+
$_SERVER['argv'] = [];
99+
$_SERVER['argc'] = 0;
100+
}
101+
96102
if (isset($options['env'])) {
97103
$_SERVER[$envKey] = $options['env'];
98104
} elseif (empty($_GET) && isset($_SERVER['argv']) && class_exists(ArgvInput::class)) {
@@ -203,10 +209,6 @@ protected static function register(GenericRuntime $runtime): GenericRuntime
203209

204210
private function getInput(): ArgvInput
205211
{
206-
if (!empty($_GET) && filter_var(ini_get('register_argc_argv'), \FILTER_VALIDATE_BOOL)) {
207-
throw new \Exception('CLI applications cannot be run safely on non-CLI SAPIs with register_argc_argv=On.');
208-
}
209-
210212
if (isset($this->input)) {
211213
return $this->input;
212214
}

0 commit comments

Comments
 (0)