Skip to content

[DependencyInjection] Escape parameters before resolving env placeholders #61276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ public function compile(bool $resolveEnvPlaceholders = false)

if ($bag instanceof EnvPlaceholderParameterBag) {
if ($resolveEnvPlaceholders) {
$this->parameterBag = new ParameterBag($this->resolveEnvPlaceholders($bag->all(), true));
$this->parameterBag = new ParameterBag($this->resolveEnvPlaceholders($this->escapeParameters($bag->all()), true));
}

$this->envPlaceholders = $bag->getEnvPlaceholders();
Expand Down Expand Up @@ -1728,4 +1728,18 @@ private function inVendors(string $path): bool

return $this->pathsInVendor[$path] = false;
}

private function escapeParameters(array $parameters): array
{
$params = [];
foreach ($parameters as $k => $v) {
$params[$k] = match (true) {
\is_array($v) => $this->escapeParameters($v),
\is_string($v) => str_replace('%', '%%', $v),
default => $v,
};
}

return $params;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ public function testCompileWithResolveEnv()
$container->setParameter('bar', '%% %env(DUMMY_ENV_VAR)% %env(DUMMY_SERVER_VAR)% %env(HTTP_DUMMY_VAR)%');
$container->setParameter('foo', '%env(FOO)%');
$container->setParameter('baz', '%foo%');
$container->setParameter('qux', '%%quux%%');
$container->setParameter('env(HTTP_DUMMY_VAR)', '123');
$container->register('teatime', 'stdClass')
->setProperty('foo', '%env(DUMMY_ENV_VAR)%')
Expand Down Expand Up @@ -1128,7 +1129,7 @@ public function testAddObjectResource()

$this->assertCount(1, $resources);

/** @var \Symfony\Component\Config\Resource\FileResource $resource */
/** @var FileResource $resource */
$resource = end($resources);

$this->assertInstanceOf(FileResource::class, $resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ protected function deleteTmpDir()
continue;
}
if ($path->isDir()) {
rmdir($path->__toString());
@rmdir($path->__toString());
} else {
unlink($path->__toString());
@unlink($path->__toString());
}
}
rmdir($this->tmpDir);
Expand Down