Summary
LangChain's older runtime serialization paths deserialize run inputs, outputs, and other payloads using overly broad object allowlists, effectively permitting any LangChain-serializable object to be revived.
When an attacker can supply serialized constructor dictionaries, they may cause trusted runtime code paths to instantiate unexpected classes with untrusted constructor arguments, expanding the attack surface for logic abuse and secondary vulnerabilities.
Affected context
This issue affects LangChain-based applications that:
- Use the framework's runtime serialization/deserialization mechanisms for runs, tools, chains, or agents.
- Accept or forward user-controlled or application-controlled serialized payloads (e.g., run inputs/outputs, tool configs, or messages) into these deserialization paths.
- Rely on default or permissive
allowed_objectsbehavior, including paths that useload(..., allowed_objects="all").
The vulnerability manifests where runtime logic trusts that only a narrow set of object types will be reinstantiated but the actual deserialization allows a broader set of LangChain-serializable classes.
Exploit preconditions
- Attack surface: Application endpoints, workflows, or message channels that:
- Accept serialized LangChain payloads (e.g., JSON/dict representations of objects), or
- Persist and later reload such payloads from storage.
- Required access: Ability to:
- Provide or influence serialized constructor dictionaries processed by LangChain's deserialization utilities, or
- Interfere with stored run state/configuration that will later be deserialized.
- Trigger point: Invocation of LangChain runtime code paths that:
- Call
load()(or equivalent) withallowed_objects="all"or overly broad allowlists, and - Use the resulting objects to perform runtime actions (such as running tools, chains, callbacks, or components).
- Why exploitation is possible:
- The deserialization logic revives any trusted LangChain-serializable object rather than enforcing a minimal, context-specific type set.
- Constructor arguments for these objects are derived from attacker-influenced serialized data, enabling instantiation of unexpected classes with untrusted parameters.
Why this happens
The core problem is unsafe deserialization with over-permissive type allowlists, aligning with CWE-502: Deserialization of Untrusted Data.
Instead of enforcing narrow, context-specific sets of permissible object types, the runtime deserialization logic can be configured with allowed_objects="all" or similarly broad rules. This means:
- Any object that LangChain considers serializable can be reconstructed, regardless of whether it is appropriate for a given runtime path.
- The framework trusts constructor dictionaries provided at runtime, allowing untrusted data to flow directly into class constructors.
Although this does not allow arbitrary Python object deserialization in the general sense, it still embodies the unsafe deserialization pattern:
- Serialized data acts as a blueprint for object graphs.
- Runtime code implicitly assumes these revived objects are safe, creating opportunities for misuse, logic manipulation, or chained exploitation when combined with other vulnerabilities.
Potential impact
- Instantiation of unexpected LangChain components with untrusted constructor arguments, which may:
- Bypass intended control flow or validation steps.
- Enable unexpected tool or chain invocation.
- Abuse of callback, tool, or agent configurations to:
- Alter agent behaviors.
- Expand an attacker's influence over how LLM outputs are processed or acted upon.
- Indirect security impacts such as:
- Triggering over-privileged components in the application.
- Escalating logical access to internal resources exposed via tools or integrations.
- Facilitation of secondary vulnerabilities if:
- Other components assume instantiated objects are trusted, or
- Constructors perform side effects or access sensitive resources.
General mitigation guidance
Mitigation strategies focus on tightening the deserialization boundary and minimizing the trust placed in runtime object reconstruction:
- Restrict object types per context:
- Configure deserialization to allow only the minimal set of object types required in a given runtime path.
- Replace broad settings like
allowed_objects="all"with explicit allowlists tailored to each use case.
- Reduce or eliminate user-controlled serialization formats:
- Avoid directly accepting raw serialized constructor dictionaries from untrusted sources.
- Introduce intermediate, strictly-typed DTOs (data transfer objects) or schemas that map to safe runtime representations.
- Validate and sanitize configuration data:
- Perform schema-based validation on serialized payloads before deserialization.
- Enforce strong invariants (e.g., allowed tool IDs, chain types, or configuration parameters) at the application boundary.
- Constrain runtime privileges:
- Ensure that instantiated objects operate under least privilege, limiting access to sensitive tools, credentials, and integrations.
- Separate high-privilege components from data/control flows that may originate from untrusted serialization inputs.
- Adopt safer serialization patterns:
- Prefer simpler, data-only structures for cross-boundary communication.
- Reserve rich object deserialization for strictly internal, trusted channels.
How teams detect issues like this
Effective detection revolves around identifying unsafe deserialization patterns and over-broad type allowlists:
- Static analysis and code scanning:
- Search for use of deserialization utilities that:
- Call
load()(or equivalent) on untrusted data. - Use
allowed_objects="all"or analogous broad configurations. - Flag call sites where deserialized objects are immediately used to:
- Instantiate tools, chains, or agents.
- Invoke callbacks or perform side-effectful operations.
- Code review focus areas:
- Examine boundaries where external or persisted data is converted into LangChain objects.
- Verify that each runtime context explicitly defines which object types may be deserialized.
- Look for constructors or factory methods that accept arbitrary dictionaries or dynamic configurations.
- Runtime monitoring and policy enforcement:
- Implement logging around deserialization events, including:
- Object types being revived.
- Sources of serialized payloads (user input, storage, messaging systems).
- Apply application-level policies that:
- Reject or quarantine unknown or unexpected object types.
- Alert when new or unusual classes appear in deserialization logs.
- Automated tooling:
- Incorporate security-focused linters or SAST tools capable of recognizing:
- Deserialization of untrusted data.
- Overly permissive object allowlists in serialization frameworks.
- Integrate these checks into CI pipelines to prevent regressions.

