Yes—this snippet is critically unsafe. In fact, it’s a textbook example of PHP object‐injection leading to remote code execution (RCE). Here’s what’s going on:
Magic “__wakeup” + eval()
Whenever PHP unserializes a PHPObjectInjection instance, it will automatically call __wakeup().
Untrusted input → arbitrary code
If an attacker can control the serialized data, they simply set the inject property to any PHP they like, and it will be executed by eval().
How an exploit looks
Imagine your app does something like:
php
// Dangerous: unserializing user data
$user_data = $_GET['data'];
$obj = unserialize($user_data);
Remove or harden magic methods
If you don’t need __wakeup(), delete it.
Sanitize/configure input
Never let users supply raw serialized blobs.
Use a secure framework
Many modern PHP frameworks implement safe serialization patterns behind the scenes.
Quick fix example
Remove the eval() entirely—or at least restrict it:
php
class PHPObjectInjection {
public $inject;
function __wakeup() {
// NEVER eval raw input
// Instead, if you must allow certain operations, use a whitelist:
$allowed = ['doThis', 'doThat'];
if (in_array($this->inject, $allowed, true)) {
call_user_func($this->inject);
}
}
}
But best practice is: don’t unserialize untrusted data and never eval user‐supplied code.