Skip to content

Instantly share code, notes, and snippets.

@mortenson
Last active June 29, 2022 17:20
Show Gist options
  • Save mortenson/7fdcb586104514bd38996b7f6093a004 to your computer and use it in GitHub Desktop.
Save mortenson/7fdcb586104514bd38996b7f6093a004 to your computer and use it in GitHub Desktop.
An idea about how to secure unserialize() calls in PHP dependencies that aren't using allowed_classes.
<?php
namespace Some\Namespace\I\Dont\Trust;
function unserialize($data, array $options = []) {
if (empty($options)) {
$options = [
'allowed_classes' => [
\DateTime::class, // Set to classes used in namespace.
],
];
}
return \unserialize($data, $options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment