Summary
LlamaIndex versions up to and including 0.11.6 contain an unsafe deserialization vulnerability in BGEM3Index.load_from_disk(), which uses pickle.load() on data from a user-supplied directory.
If an attacker can provide or influence the contents of the persist_dir, they can supply a malicious multi_embed_store.pkl file that executes arbitrary code when a victim loads the index from disk.
Affected context
This issue affects applications that integrate LlamaIndex and use BGEM3Index.load_from_disk() with a persist_dir whose contents are not fully trusted or strictly controlled.
The vulnerability is triggered when the code deserializes multi_embed_store.pkl from the specified directory using Python's pickle module.
Environments where persist directories can be influenced by other users, external services, shared storage, or uploaded artifacts are particularly exposed.
Exploit preconditions
- Attack surface: LlamaIndex-based applications that call
BGEM3Index.load_from_disk(persist_dir=...). - Required access: Ability to create or modify files within the target
persist_dirpath, either locally or via an application feature (e.g., uploads, synchronization, or shared volumes). - Trigger point: A victim process calls
BGEM3Index.load_from_disk()on an attacker-controlled or attacker-influencedpersist_dirthat contains a craftedmulti_embed_store.pkl. - Why exploitation is possible:
pickle.load()is invoked directly on untrusted data without validation, sandboxing, or type restrictions, allowing execution of arbitrary code embedded in the pickle payload.
Why this happens
The root cause is the use of Python's pickle.load() on data derived from a user-supplied directory without enforcing a trust boundary or applying validation.
pickle is a powerful but unsafe serialization format that can encode executable operations; when deserialized, these operations may run automatically as part of object reconstruction.
This maps to CWE-502: Deserialization of Untrusted Data, where untrusted input is treated as serialized objects and deserialized using mechanisms that can trigger code execution.
The abstract insecure pattern is: "deserialize attacker-controllable bytes with a code-capable serializer (pickle) in a high-privilege runtime, without constraining what can be instantiated."
Potential impact
- Execution of arbitrary code with the privileges of the LlamaIndex-using application process
- Full compromise of the host environment for the application (e.g., access to environment variables, API keys, and local data)
- Tampering with or exfiltration of sensitive index content and embedded documents
- Use of the compromised process as a pivot point for broader lateral movement in the environment
- Denial of service by causing crashes, resource exhaustion, or persistent corruption of index state
General mitigation guidance
Effective mitigation focuses on eliminating unsafe deserialization and tightening trust around persisted index data:
- Prefer serialization formats that do not support arbitrary code execution (for example, JSON, MessagePack, or other schema-based formats) instead of
picklefor persisting model and index state. - If binary formats are necessary, introduce an abstraction that strictly controls the types and structures that can be reconstructed, avoiding generic object loading.
- Treat any persisted index directory (
persist_dir) as sensitive configuration data: restrict write access to trusted components and avoid using directories influenced by user uploads or shared workspaces. - Apply least-privilege principles to the process loading indexes (e.g., limited filesystem permissions, confined containers, or sandboxes) to reduce the blast radius if deserialization issues occur.
- Introduce integrity and provenance checks (such as signatures, checksums, or trusted storage backends) before loading persistence artifacts from disk.
How teams detect issues like this
Organizations can detect and monitor this class of issue through a mix of code-centric and operational techniques:
- Static analysis: Configure static analysis or linters to flag uses of
pickle.load(),pickle.loads(), or similar APIs, especially when the source is derived from user input, configurable paths, or network-accessible storage. - Code review patterns: During review, treat any deserialization of on-disk or remote data as security-sensitive; require explicit documentation of trust boundaries for
persist_dirand justification for usingpickle. - Security policy enforcement: Establish guidelines that discourage or forbid unsafe serializers in production components, backed by automated checks in CI/CD (e.g., searching for
pickleusage in critical modules). - Runtime monitoring: Instrument file access and process behavior around index loading routines to detect unexpected access patterns, unusual persist directories, or anomalous behaviors after loading.

