Skip to content

Commit 6a3c86c

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 ------- b4201810b9 Conditionally add options to unserialize in PHP 7.0+.
2 parents 81aff72 + 1451341 commit 6a3c86c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

FormError.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ public function serialize()
185185
*/
186186
public function unserialize($serialized)
187187
{
188-
list($this->message, $this->messageTemplate, $this->messageParameters, $this->messagePluralization, $this->cause) = unserialize($serialized);
188+
if (PHP_VERSION_ID >= 70000) {
189+
list($this->message, $this->messageTemplate, $this->messageParameters, $this->messagePluralization, $this->cause) = unserialize($serialized, array('allowed_classes' => false));
190+
} else {
191+
list($this->message, $this->messageTemplate, $this->messageParameters, $this->messagePluralization, $this->cause) = unserialize($serialized);
192+
}
189193
}
190194
}

0 commit comments

Comments
 (0)