Dont allow unserializing classes with a destructor - 5.2

This commit is contained in:
Jérémy Derussé 2020-12-15 11:45:32 +01:00
parent 6caf916083
commit 98601908bb
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2
3 changed files with 24 additions and 0 deletions

View File

@ -127,6 +127,16 @@ trait CommonResponseTrait
return $stream;
}
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
/**
* Closes the response and all its network handles.
*/

View File

@ -44,6 +44,16 @@ class TraceableResponse implements ResponseInterface, StreamableInterface
$this->event = $event;
}
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
public function __destruct()
{
try {

View File

@ -104,6 +104,10 @@ final class TokenBucket implements LimiterStateInterface
*/
public function __wakeup(): void
{
if (!\is_string($this->stringRate)) {
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
$this->rate = Rate::fromString($this->stringRate);
unset($this->stringRate);
}