/

CVE-2024-14021

Severity:

HIGH RISK

(7.8)

Unsafe Deserialization in LlamaIndex

CVE-2024-14021

Analyzed

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Remote Code Execution

Severity:

HIGH RISK

(7.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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_dir path, 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-influenced persist_dir that contains a crafted multi_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 pickle for 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_dir and justification for using pickle.
  • 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 pickle usage 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.

Sources

SourceLink
github.comgithub.com/run-llama/llama_index
huntr.comhuntr.com/bounties/ab4ceeb4-aa85-4d1c-aaca-4eda1b71fc12
llamaindex.aillamaindex.ai/
vulncheck.comvulncheck.com/advisories/llamaindex-bgem3index-unsafe-deserialization

Frequently asked

questions

It can be, depending on how the application exposes persist_dir. If an attacker can cause the application to load an index from a directory they control (for example, via uploads, shared storage, or configurable paths), they may be able to exploit it remotely. If persist_dir is strictly local and not influenced by external users, the risk is reduced.

The attacker must be able to create or modify multi_embed_store.pkl inside a directory that the victim later passes to BGEM3Index.load_from_disk(). This access might be direct filesystem access, write access to shared volumes, or indirect control through an application feature that writes files into the persist directory.

Replace pickle-based deserialization with a safer, non-code-executing format and ensure that only strictly validated, schema-constrained data is loaded. In addition, treat any persisted index directory as trusted-only data, blocking untrusted users from writing into it.

Establish a development policy that discourages the use of general-purpose code-capable serializers (like pickle) for untrusted or semi-trusted data, add automated checks for dangerous deserialization APIs, and require explicit documentation and review of any data-loading routines that cross trust boundaries. Designing storage layers around safe, structured formats from the outset significantly lowers the risk of unsafe deserialization flaws.

Find out what's already
exploitable in your codebase.