Join our Newsletter — 33% off our NHI Course
Home› Glossary› Cyber Security› Python Object Injection
Cyber Security

Python Object Injection

← Back to Glossary
By NHI Mgmt Group Updated November 25, 2026 Domain: Cyber Security

Python object injection is a vulnerability where attacker-controlled data is turned into Python objects during deserialisation or dynamic evaluation. It commonly appears when code uses unsafe loaders, eval-like functions, or pickled data from untrusted sources, allowing arbitrary object creation and sometimes code execution.

What Python Object Injection Is

Python object injection happens when untrusted input is converted into Python objects during deserialisation or dynamic evaluation. That makes the application trust attacker-controlled structure, not just attacker-controlled text, so the payload can influence object state, invoke unexpected methods, or trigger code execution paths that the developer never intended.

How It Becomes Dangerous

The risk comes from the gap between “data” and “behaviour”. Python features such as unsafe loaders, pickle-like deserialisation, and eval-style processing can reconstruct objects with rich behaviour, and some object graphs become dangerous as soon as they are materialised. If the application accepts content from users, APIs, files, queues, or plugins without strict controls, the deserialiser can become an execution boundary instead of a parsing step.

That is why object injection is usually discussed alongside insecure deserialisation, gadget chains, and remote code execution. The vulnerability is not limited to one library or one code pattern, because the core issue is allowing attacker influence over how the runtime interprets the input into executable object behaviour.

Common Exposure Patterns

Python object injection often appears in code that assumes a trusted source, then later reuses the same path for external input. A service may deserialize a cached object, a webhook payload, a message-queue event, or a developer convenience format that was never meant to cross a trust boundary. In practice, the danger increases when the code uses dynamic evaluation, permissive object reconstruction, or libraries that can resolve arbitrary classes or callables.

Reviewing exposure usually starts with a simple question: can external data reach a parser that creates Python objects rather than plain values? If the answer is yes, the next question is whether the parser is restricted to an allowlist of safe types, whether dangerous constructors are blocked, and whether the application treats the resulting object as trusted state.

For deeper patterns and defensive design, see the Insecure Deserialisation Guide and the Secure Deserialisation Guide, which cover gadget chains, fail-closed loaders, and safe type constraints across languages including Python.

Why It Matters for Python Applications

Python’s flexibility is part of the problem. Developers often reach for convenience features that make code concise, but those same features can blur the boundary between controlled program logic and attacker-influenced object creation. When exploitation succeeds, the impact can range from application corruption and logic manipulation to full compromise of the host process.

In Python ecosystems, this also intersects with supply-chain trust and unsafe dependency usage. A package, plugin, or framework component that deserializes untrusted input can expose every downstream service that depends on it. For a broader view of Python-specific application risk, the PHP and WordPress Security Guide is not directly about Python, but it reflects the same application-hardening principle: reduce attack surface by constraining dangerous runtime features and dependency paths.

At the control level, object injection is a classic example of why secure defaults, strict parsing, and deny-by-default data handling matter. For application risk baselines, the OWASP Top 10 remains a useful reference for framing injection and unsafe processing as core web application security concerns.

Risk and Threat Considerations

Python object injection is dangerous because it can turn ordinary input handling into a code-execution path. Attackers look for deserialisers, evaluators, and object loaders that accept external data, then supply payloads that create unexpected objects, trigger gadget behaviour, or bypass intended validation.

Failure mechanism: A parser reconstructs attacker-controlled object graphs or evaluates attacker-supplied expressions, and the resulting object behaviour executes with the application’s privileges.

Impact: The outcome can include remote code execution, session or credential theft from the process environment, tampering with application logic, and persistence through modified state or follow-on payload delivery.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP ASVSV1 — Encoding and SanitizationObject injection starts with unsafe handling of externally supplied input.
V15 — Secure Coding and ArchitecturePython object injection is a design flaw in unsafe object creation paths.
Recommendation — Validate and constrain input before it reaches deserialisers or evaluators. Remove unsafe object reconstruction paths and use fixed-type data contracts.
NIST SP 800-53 Rev 5SI-10 — Information Input ValidationThis vulnerability is driven by insufficient validation of attacker-controlled data.
SC-18 — Mobile CodeDynamic evaluation and executable content handling create code-execution risk.
Recommendation — Enforce strict input validation before parsing or object creation. Restrict dynamic code execution and treat executable input as untrusted.
CIS Controls v816 — Application Software SecurityThe issue is an application-layer security weakness in deserialisation and evaluation logic.
Recommendation — Harden application code paths that deserialize or evaluate external input.

Practitioner Guidance

Why practitioners should care: The safest response is to treat every deserialisation or dynamic-evaluation entry point as a security boundary. In Python, that means preferring simple data formats and fixed schemas over object reconstruction, and assuming that convenience helpers are unsafe until proven otherwise.

What to watch for: Look for pickle usage, generic object loaders, eval-like functions, custom deserialisation hooks, and any code path that accepts structured input from outside the trust boundary. Review how those paths behave under untrusted input, not just under happy-path test data.

Practitioner takeaway: If the application does not absolutely need to recreate Python objects from external input, it should not do so. The more the input is allowed to shape runtime objects, the more the parser becomes an attacker-controlled execution primitive.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org