agentsclimarketplace

Security unserialize

Skill AravindS-Wick/aravindhan-skills/skills/security-unserialize

Prevent serialization vulnerabilities when using serialize, unserialize, or magic methods. Use when generating or editing PHP code with serialization; follows .agent/rules/security-unserialize.mdc.From its SKILL.md

Install
npx -y skills add AravindS-Wick/aravindhan-skills --skill security-unserialize

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

1.9 KB, 375 tokens by cl100k_base, as published. Nobody here has run it

PHP Serialization Vulnerability Protection

PHP Serialization Functions

PHP provides the builtin serialize and unserialize functions. These functions should be avoided if JSON encoding can be used instead. The serialization functions should only be used if complex objects with many properties need to be encoded into a serialized representation. If serialization is used, the unserialize calls that reconstruct this data into objects MUST be limited to only instantiate a hard coded list of classes that are expected to be in the input passed to unserialize. Here is an example:

class DataItem {
    public $data;
    public function __construct($data) {$this->data = $data;}
}
 
// the only place we produce input I expect to be consumed by restoreAction()
function saveAction()
{
    $data = new DataItem("foo");
    $id = 1;
    saveToDatabase($id, serialize($data));
}
 
function restoreAction()
{
    $id = 1;
    // Only DataItem class objects should ever be present in this input to unserialize()
    $data = unserialize(restoreFromDatabase($id), ['allowed_classes' => ['DataItem']]);
}

If working with existing code that uses serialization, but does not need to support any classes and only contains data consisting of native PHP types (integers, strings, arrays, etc.) modify the code to not allow unserialization of classes:

    $serialized_str = $this->request->getParam("serialized_input");
    $str = unserialize($serialized_str, ['allowed_classes' => false]); // no classes allowed

PHP Magic Class Methods

PHP supports magic methods. Some of these methods can be abused as part of a serialization vulnerability. Never generate the following methods for a class:

  • __sleep()
  • __wakeup()
  • __destruct()

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,835. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.