xkerman/restricted-unserialize
Composer 安装命令:
composer require xkerman/restricted-unserialize
包简介
provide PHP Object Injection safe unserialize function
README 文档
README
This composer package provides unserialize function that is safe for PHP Obejct Injection (POI).
If normal unserialize function is used for deserializing user input in your PHP application:
- Don't use this package, use
json_decodein order to avoid PHP Object Injection - If compatibility matters, first use this function and then try to use
json_decodein the near future
Why POI-safe?
unserialize function in this package only deserializes boolean, integer, floating point number, string, and array, and not deserializes object instance.
Since any instances that has magic method for POP chain (such as __destruct or __toString) cannot instantiate, any plan to exploit POP chain just fails.
( You can read detailed explanation of POP chain https://www.insomniasec.com/downloads/publications/Practical%20PHP%20Object%20Injection.pdf )
Installation
$ composer require xkerman/restricted-unserialize
How to use
if your PHP version > 5.5:
require 'path/to/vendor/autoload.php';
use function xKerman\Restricted\unserialize;
use xKerman\Restricted\UnserializeFailedException;
try {
var_dump(unserialize($data));
} catch (UnserializeFailedException $e) {
echo 'failed to unserialize';
}
if your PHP version >= 5.3 and <= 5.5:
require 'path/to/vendor/autoload.php';
use xKerman\Restricted;
use xKerman\Restricted\UnserializeFailedException;
try {
var_dump(Restricted\unserialize($data));
} catch (UnserializeFailedException $e) {
echo 'failed to unserialize';
}
if your PHP version is 5.2:
require_once 'path/to/generated/src/xKerman/Restricted/bootstrap.php';
try {
var_dump(xKerman_Restricted_unserialize($data));
} catch (xKerman_Restricted_UnserializeFailedException $e) {
echo 'failed to unserialize';
}
Related other packages
mikegarde/unserialize-fix
mikegarde/unserialize-fix package provides \unserialize\fix function that tries to use unserialize function first. So the function is not POI-safe.
academe/serializeparser
academe/serializeparser package privides \Academe\SerializeParser\Parser::parse method that is PHP-implemented unserialize, but doesn't deserialize object instances. So the method seems that POI-safe, but there is no test.
jeroenvdheuve/serialization
jeroenvdheuve/serialization package provides \jvdh\Serialization\Unserializer\unserialize method that is also PHP-implemented unserialize, and doesn't deserialize object instance. So the method seems that POI-safe.
The method can deserialize serialized PHP references, which cannot deserialized by this (xkerman/restricted-unserilize) package. By using PHP reference, we can create cyclic structure, but that makes migration to json_decode harder, since JSON doesn't support cyclic structure decode/encode.
Development
To generate code for PHP 5.2, run composer run generate.
Generated code will be saved under genereated/ directory.
LICENSE
MIT License
xkerman/restricted-unserialize 适用场景与选型建议
xkerman/restricted-unserialize 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 617.83k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 10 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「unserialize」 「deserialize」 「PHP Object Injection」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xkerman/restricted-unserialize 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xkerman/restricted-unserialize 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xkerman/restricted-unserialize 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Transform loose and complex input into consistent, strongly-typed data structures
Dead simple functional library for object prototyping, data hydration and data exposition
Runn Me! Serialization Library
Zend Framework 2 Module that integrates the jms serializer library
Alfabank REST API integration
Provides an interface for unserializer classes to implement.
统计信息
- 总下载量: 617.83k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 28
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-09