|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-04-17 05:38 UTC] bishop@php.net
-Status: Open
+Status: Assigned
-Assigned To:
+Assigned To: bishop
[2019-04-17 05:40 UTC] bishop@php.net
[2019-04-17 05:41 UTC] bishop@php.net
[2020-08-05 00:36 UTC] tandre@php.net
[2025-10-25 10:31 UTC] nielsdos@php.net
-Status: Assigned
+Status: Closed
[2025-10-25 10:31 UTC] nielsdos@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 04:00:01 2025 UTC |
Description: ------------ It's currently possible to serialize concrete types in a phar metadata, which opens us up to the potential for deserialization attacks through gadget chains. Since PHAR files can serialize concrete types, they can serialize chains of objects that, when deserialized, fire __construct __destruct and __wakeup. This is an issue largely because PHP will automatically deseralize this payload in the following case: `file_exists('phar://path/to/phar')` which has cauused RCE in a couple projects in the wild including Typo3 https://typo3.org/security/advisory/typo3-core-sa-2018-002/ I propose that we disable the ability to have concrete types included in the serialized metadata by providing an empty classlist to the unserialize call in the PHAR package. This will support the real cases we see in the wild of metadata usage which is only array key values. Test script: --------------- <?php class Foo { public function __wakeup() { die('FIRED WAKEUP UNEXPECTEDLY'); } } $file = './test.phar'; if (!file_exists($file)) { $p = new Phar($file); $p->setStub(Phar::createDefaultStub(__FILE__)); $p->addFile(__FILE__); // pointing main file which requires all classes $p->setMetadata(new Foo()); $p->compress(Phar::GZ); } // Trigger unsafe deserialization file_exists($file); Expected result: ---------------- File_exists currently loads the entire metadata for the phar. If this is intended, I'd expect the metadata to safely unserialize without fire any magic methods. Actual result: -------------- Magic methods get fired