Skip to content

Commit 22542ac

Browse files
committed
minor #21090 Secure unserialize by restricting allowed classes when using PHP 7 (dbrumann)
This PR was merged into the 3.3-dev branch. Discussion ---------- Secure unserialize by restricting allowed classes when using PHP 7 | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | --- | License | MIT | Doc PR | --- While playing around with Symfony in a PHP 7.1 application I noticed a warning in how EnvParameterResoure uses unserialize. Since PHP 7.0 introduced the options argument which allows to restrict which classes can be unserialized for better security, it might make sense to use it here. As far as I can tell this is no BC break, it only provides an additional safety mechanism. Commits ------- b420181 Conditionally add options to unserialize in PHP 7.0+.
2 parents 9e94899 + 4ca9fee commit 22542ac

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Config/EnvParametersResource.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ public function serialize()
7272

7373
public function unserialize($serialized)
7474
{
75-
$unserialized = unserialize($serialized);
75+
if (PHP_VERSION_ID >= 70000) {
76+
$unserialized = unserialize($serialized, array('allowed_classes' => false));
77+
} else {
78+
$unserialized = unserialize($serialized);
79+
}
7680

7781
$this->prefix = $unserialized['prefix'];
7882
$this->variables = $unserialized['variables'];

Debug/FileLinkFormatter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ public function serialize()
6363

6464
public function unserialize($serialized)
6565
{
66-
$this->fileLinkFormat = unserialize($serialized);
66+
if (PHP_VERSION_ID >= 70000) {
67+
$this->fileLinkFormat = unserialize($serialized, array('allowed_classes' => false));
68+
} else {
69+
$this->fileLinkFormat = unserialize($serialized);
70+
}
6771
}
6872

6973
private function getFileLinkFormat()

Kernel.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,11 @@ public function serialize()
763763

764764
public function unserialize($data)
765765
{
766-
list($environment, $debug) = unserialize($data);
766+
if (PHP_VERSION_ID >= 70000) {
767+
list($environment, $debug) = unserialize($data, array('allowed_classes' => false));
768+
} else {
769+
list($environment, $debug) = unserialize($data);
770+
}
767771

768772
$this->__construct($environment, $debug);
769773
}

0 commit comments

Comments
 (0)