Object Injection Deserialization logo

Object Injection Deserialization

Organization
wpultimatesecurity
object-injection-deserialization

Use when code calls unserialize, maybe_unserialize, or stores serialized PHP in options, meta, or transients from untrusted input. Avoids unserialize on attacker-controlled data, prefers json_encode / json_decode, and when unserialize is unavoidable passes ['allowed_classes' => false]. Prevents PHP object injection and POP-chain remote code execution.

Overview

Publisherwpultimatesecurity
RepositoryWordPress-Security-Skills
Skill nameobject-injection-deserialization
Stars
54
Forks
3
Bundled files
2
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by wpultimatesecurity on GitHub. Read the source before you install it.

Installation

Install the Object Injection Deserialization AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/object-injection-deserialization
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wpultimatesecurity/WordPress-Security-Skills.git /tmp/WordPress-Security-Skills
mkdir -p .claude/skills
cp -r /tmp/WordPress-Security-Skills/skills/object-injection-deserialization .claude/skills/object-injection-deserialization
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Object Injection Deserialization in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Object Injection Deserialization on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Object Injection Deserialization is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Object injection & deserialization security

When to use this skill

Use this skill whenever code touches PHP serialization:

  • Calling unserialize(), maybe_unserialize(), or is_serialized() on user input.
  • Storing serialized arrays/objects in options, post meta, user meta, or transients.
  • Importing data from files, feeds, or uploads that may contain serialized PHP.
  • Migrating or caching objects by serializing them.

PHP object injection lets an attacker instantiate arbitrary objects and trigger magic methods (__wakeup(), __destruct(), __toString()) that form POP (property-oriented programming) chains, often leading to remote code execution.

Core principles (and why they matter)

  1. Never unserialize() untrusted input. Anything from $_POST, $_GET, files, remote APIs, or cookies is untrusted.
  2. Prefer JSON for interchange. wp_json_encode() / json_decode() only produces arrays/stdClass and cannot instantiate PHP classes, breaking object-injection chains.
  3. maybe_unserialize() is still unserialize(). It just checks is_serialized() first. Do not use it on attacker-controlled data.
  4. If forced to unserialize, disable classes. Pass array( 'allowed_classes' => false ) (PHP 7.0+) to unserialize() so no objects are instantiated.
  5. Do not trust is_serialized() as a safety check. It only tells you the format; it does not make the payload safe.
  6. Keep serialized objects out of user-facing storage. Options and meta that users can influence should store JSON or scalar values.

Step-by-step implementation

  1. Identify every unserialize(), maybe_unserialize(), and is_serialized() call.
  2. Determine whether the data is attacker-controllable. If yes, replace with JSON.
  3. For trusted internal serialization, use allowed_classes => false or a narrow allowlist of classes.
  4. Validate the decoded shape (expected keys/types) before use.
  5. Escape any values from the decoded data before output.

Supporting references

ReferenceLoad when
Object injection & deserialization checklistBefore final verification of the object injection & deserialization controls.
Secure deserialization and importImplementing validated JSON imports and disabling class instantiation where trusted deserialization is unavoidable.

Common AI mistakes / anti-patterns

Mistake 1 — unserialize() on $_POST

php
// ❌ Insecure: arbitrary object instantiation.
$data = unserialize( $_POST['config'] );
php
// ✅ Secure: use JSON for user-supplied structured data.
$raw  = isset( $_POST['config'] ) ? wp_unslash( $_POST['config'] ) : '';
$data = json_decode( $raw, true );
if ( ! is_array( $data ) ) {
    wp_die( esc_html__( 'Invalid configuration.', 'my-plugin' ), 400 );
}
$api_key = isset( $data['api_key'] ) ? sanitize_text_field( $data['api_key'] ) : '';

Mistake 2 — Treating maybe_unserialize() as safe

php
// ❌ Insecure: maybe_unserialize is unserialize with a format check.
$config = maybe_unserialize( file_get_contents( $uploaded_file ) );
php
// ✅ Secure: read and validate JSON instead.
$raw      = file_get_contents( $uploaded_file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$decoding = json_decode( $raw, true );
if ( null === $decoding && json_last_error() !== JSON_ERROR_NONE ) {
    wp_die( esc_html__( 'Invalid import file.', 'my-plugin' ), 400 );
}

Mistake 3 — Trusting is_serialized()

php
// ❌ Insecure: is_serialized only describes the format.
if ( is_serialized( $value ) ) {
    $value = unserialize( $value ); // still dangerous
}
php
// ✅ Secure: if you must accept serialized data, disable class instantiation.
if ( is_serialized( $value ) ) {
    $value = @unserialize( $value, array( 'allowed_classes' => false ) );
}

Mistake 4 — Storing user-supplied serialized blobs

php
// ❌ Insecure: stores attacker-controlled serialized payload in meta.
update_post_meta( $post_id, '_my_plugin_data', $_POST['data'] );
php
// ✅ Secure: store JSON; validate and sanitize on read.
$raw  = isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '';
$data = json_decode( $raw, true );
if ( is_array( $data ) ) {
    update_post_meta( $post_id, '_my_plugin_data', wp_json_encode( $data ) );
}

Mistake 5 — Serializing objects for cache/transients without class restrictions

php
// ❌ Risky: transient value can instantiate arbitrary objects on read.
set_transient( 'my_plugin_state', serialize( $object ) );
php
// ✅ Safer: store JSON or, if objects are required, a known shape with allowed_classes false.
set_transient( 'my_plugin_state', wp_json_encode( $object ) );

Correct code examples

A safe importer that rejects serialized PHP and parses JSON is in references/secure-deserialization.php.

Checklist

  • No unserialize() / maybe_unserialize() runs on user input, uploads, or remote data.
  • JSON is used for structured data interchange.
  • Where unserialize() is unavoidable, allowed_classes => false is set.
  • is_serialized() is not treated as a security check.
  • Serialized blobs are not stored from user-controlled sources.
  • Decoded JSON is validated for expected shape before use.
  • Values from decoded data are sanitized/escaped before output.

Official references

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Object Injection Deserialization AI skill do?

Use when code calls unserialize, maybe_unserialize, or stores serialized PHP in options, meta, or transients from untrusted input. Avoids unserialize on attacker-controlled data, prefers json_encode / json_decode, and when unserialize is unavoidable passes ['allowed_classes' => false]. Prevents PHP object injection and POP-chain remote code execution.

Why use Object Injection Deserialization on TypingMind?

Because you install it once and use it with any model. Object Injection Deserialization is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Object Injection Deserialization in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/object-injection-deserialization. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Object Injection Deserialization?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Object Injection Deserialization?

As many as you like. As long as a model supports skills, you can use Object Injection Deserialization with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Object Injection Deserialization AI skill free?

Yes. It is published on GitHub by wpultimatesecurity under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇