2017 © Pedro Peláez
 

library serial

A safe unserializer for PHP serialized arrays and scalar types.

image

lyte/serial

A safe unserializer for PHP serialized arrays and scalar types.

  • Monday, June 25, 2018
  • by lyte
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,187 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 23640 % Grown

The README.md

PHP Lyte Serial

Build Status Coverage Status, (*1)

PHP Serialized string array and scalar unserialization using pure PHP., (*2)

Usage

Install with composer:, (*3)

composer require lyte/serial

Serial

Serial is a simplified interface that attempts to work well in a legacy code base., (*4)

Load the namespace:, (*5)

use Lyte\Serial\Serial;
// unserialize statically
$unserialized = Serial::unserialize($someSerializedString);
// or with an instance
$serial = new Serial;
$unserialized = $serial->unserialize($someSerializedString);

// check if a string appears to be serialized
if (Serial::isSerialized($someUnknownString)) {
    $unserialized = Serial::unserialize($someUnknownString);
}

// or rely on exceptions
try {
    $unserialized = Serial::unserialize($someUnknownString);
} catch (\Exception $e) {
    // ...
}

Unserializer

Unserializer is the internal work horse., (*6)

use Lyte\Serial\Unserializer;
$serial = new Unserializer($someSerializedString);
$unserialized = $serial->unserialize();

Why?

The standard serialize() and unserialize() calls in PHP are known to be unsafe even if you use the $allowed_classes filter in PHP 7 (there are memory corruption bugs)., (*7)

The standard answer to this is "use JSON" but some applications were using PHP serialized strings for internal storage long before JSON was a thing (well... popular)., (*8)

In this case it may be useful to have a safer parser that rejects anything that's not an array or scalar type (i.e what you could safely store in JSON) as a middle ground to harden a code base without having to immediately switch out the underlying storage format., (*9)

Note: I'm not advocating letting any strings be unserialized that can in anyway be modified by a user, just that if you use a safer parser and someone compromises some other part of your application this might at least slow them down., (*10)

Why can't I use $allowed_classes?

PHP 7 added the $allowed_classes option to the unserialize() function., (*11)

In theory you could just set this to null (or a safe set of classes), but unfortunately there's memory corruption bugs meaning if you rely on that behaviour, you are vulnerable., (*12)

The Versions

25/06 2018

dev-master

9999999-dev

A safe unserializer for PHP serialized arrays and scalar types.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Schoen

25/06 2018

0.1.0

0.1.0.0

A safe unserializer for PHP serialized arrays and scalar types.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Schoen

25/06 2018

dev-expose-php-notices

dev-expose-php-notices

A safe unserializer for PHP serialized arrays and scalar types.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Schoen

25/06 2018

dev-new-php-versions

dev-new-php-versions

A safe unserializer for PHP serialized arrays and scalar types.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Schoen

25/06 2018

dev-is-serialized

dev-is-serialized

A safe unserializer for PHP serialized arrays and scalar types.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Schoen

19/06 2017

dev-coverage

dev-coverage

A safe unserializer for PHP serialized arrays and scalar types.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Schoen

19/06 2017

0.0.1

0.0.1.0

A safe unserializer for PHP serialized arrays and scalar types.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Schoen

10/06 2017

0.0.0

0.0.0.0

A safe unserializer for PHP serialized arrays and scalar types.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Schoen