Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9ee8aab

Browse filesBrowse files
committed
[DependencyInjection] protect environment variables stored in parameters
1 parent 26acc8f commit 9ee8aab
Copy full SHA for 9ee8aab

File tree

Expand file treeCollapse file tree

2 files changed

+16
-10
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-10
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
16+
use Symfony\Component\DependencyInjection\EnvVariable;
1617

1718
/**
1819
* Resolves all parameter placeholders "%somevalue%" to their real values.
@@ -34,9 +35,9 @@ public function process(ContainerBuilder $container)
3435

3536
foreach ($container->getDefinitions() as $id => $definition) {
3637
try {
37-
$definition->setClass($parameterBag->resolveValue($definition->getClass()));
38+
$definition->setClass($parameterBag->resolveValue($definition->getClass(), array(), true));
3839
$definition->setFile($parameterBag->resolveValue($definition->getFile()));
39-
$definition->setArguments($parameterBag->resolveValue($definition->getArguments()));
40+
$definition->setArguments($parameterBag->resolveValue($definition->getArguments(), array(), true));
4041
if ($definition->getFactoryClass(false)) {
4142
$definition->setFactoryClass($parameterBag->resolveValue($definition->getFactoryClass(false)));
4243
}
@@ -50,11 +51,11 @@ public function process(ContainerBuilder $container)
5051

5152
$calls = array();
5253
foreach ($definition->getMethodCalls() as $name => $arguments) {
53-
$calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
54+
$calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments, array(), true);
5455
}
5556
$definition->setMethodCalls($calls);
5657

57-
$definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
58+
$definition->setProperties($parameterBag->resolveValue($definition->getProperties(), array(), true));
5859
} catch (ParameterNotFoundException $e) {
5960
$e->setSourceId($id);
6061

‎src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\ParameterBag;
1313

14+
use Symfony\Component\DependencyInjection\EnvVariable;
1415
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
1516
use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;
1617
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@@ -167,12 +168,12 @@ public function resolve()
167168
* @throws ParameterCircularReferenceException if a circular reference if detected
168169
* @throws RuntimeException when a given parameter has a type problem.
169170
*/
170-
public function resolveValue($value, array $resolving = array())
171+
public function resolveValue($value, array $resolving = array(), $protectEnvVariables = false)
171172
{
172173
if (is_array($value)) {
173174
$args = array();
174175
foreach ($value as $k => $v) {
175-
$args[$this->resolveValue($k, $resolving)] = $this->resolveValue($v, $resolving);
176+
$args[$this->resolveValue($k, $resolving, $protectEnvVariables)] = $this->resolveValue($v, $resolving, $protectEnvVariables);
176177
}
177178

178179
return $args;
@@ -182,7 +183,7 @@ public function resolveValue($value, array $resolving = array())
182183
return $value;
183184
}
184185

185-
return $this->resolveString($value, $resolving);
186+
return $this->resolveString($value, $resolving, $protectEnvVariables);
186187
}
187188

188189
/**
@@ -197,7 +198,7 @@ public function resolveValue($value, array $resolving = array())
197198
* @throws ParameterCircularReferenceException if a circular reference if detected
198199
* @throws RuntimeException when a given parameter has a type problem.
199200
*/
200-
public function resolveString($value, array $resolving = array())
201+
public function resolveString($value, array $resolving = array(), $protectEnvVariables = false)
201202
{
202203
// we do this to deal with non string values (Boolean, integer, ...)
203204
// as the preg_replace_callback throw an exception when trying
@@ -211,10 +212,14 @@ public function resolveString($value, array $resolving = array())
211212

212213
$resolving[$key] = true;
213214

214-
return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key), $resolving);
215+
return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key), $resolving, $protectEnvVariables);
215216
}
216217

217218
if (preg_match('/^\$([^\$\s]+)\$$/', $value, $match)) {
219+
if ($protectEnvVariables) {
220+
return new EnvVariable($match[1]);
221+
}
222+
218223
return getenv($match[1]);
219224
}
220225

@@ -240,7 +245,7 @@ public function resolveString($value, array $resolving = array())
240245
$resolved = (string) $resolved;
241246
$resolving[$key] = true;
242247

243-
return $self->isResolved() ? $resolved : $self->resolveString($resolved, $resolving);
248+
return $self->isResolved() ? $resolved : $self->resolveString($resolved, $resolving, $protectEnvVariables);
244249
}, $value);
245250
}
246251

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.