Skip to content

Commit 68d4885

Browse files
[DI] Use reproducible entropy to generate env placeholders
1 parent 80c6d9e commit 68d4885

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ParameterBag/EnvPlaceholderParameterBag.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class EnvPlaceholderParameterBag extends ParameterBag
2424
private $unusedEnvPlaceholders = [];
2525
private $providedTypes = [];
2626

27+
private static $counter = 0;
28+
2729
/**
2830
* {@inheritdoc}
2931
*/
@@ -57,7 +59,7 @@ public function get($name)
5759
}
5860
}
5961

60-
$uniqueName = md5($name.uniqid(mt_rand(), true));
62+
$uniqueName = md5($name.'_'.self::$counter++);
6163
$placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), str_replace(':', '_', $env), $uniqueName);
6264
$this->envPlaceholders[$env][$placeholder] = $placeholder;
6365

@@ -72,7 +74,13 @@ public function get($name)
7274
*/
7375
public function getEnvPlaceholderUniquePrefix(): string
7476
{
75-
return $this->envPlaceholderUniquePrefix ?? $this->envPlaceholderUniquePrefix = 'env_'.bin2hex(random_bytes(8));
77+
if (null === $this->envPlaceholderUniquePrefix) {
78+
$reproducibleEntropy = unserialize(serialize($this->parameters));
79+
array_walk_recursive($reproducibleEntropy, function (&$v) { $v = null; });
80+
$this->envPlaceholderUniquePrefix = 'env_'.substr(md5(serialize($reproducibleEntropy)), -16);
81+
}
82+
83+
return $this->envPlaceholderUniquePrefix;
7684
}
7785

7886
/**

0 commit comments

Comments
 (0)