Summary
DiskCache (python-diskcache) uses Python's pickle module for serialization by default, allowing cached values to embed executable payloads.
If an attacker can write to the cache directory, they can plant malicious cache entries that trigger arbitrary code execution when a victim application later reads from the cache.
Affected context
This vulnerability affects Python applications that integrate DiskCache with its default pickle-based serializer and store cache data in locations where untrusted parties may gain write access.
The risk is most pronounced when:
- Cache directories reside on shared or world-writable filesystems
- Multiple users or services share the same cache path
- Cache integrity is assumed but not enforced by the application
Exploit preconditions
- Attack surface: Local or adjacent system level, via the filesystem that hosts the DiskCache cache directory.
- Required access: Ability to create, modify, or replace cache files and directories used by DiskCache (e.g., through local user access, shared volume, or compromised service).
- Trigger point: Any application code path that reads from DiskCache and deserializes cached objects using the default pickle-based serializer.
- Why exploitation is possible: Pickle is a code-capable serialization format; deserializing attacker-controlled data can execute arbitrary Python code during unpickling, and DiskCache's default configuration trusts cache contents without integrity checks or isolation.
Why this happens
The core issue is the use of Python's pickle module as a default serialization mechanism for cache values without restricting who can write to the underlying cache store.
Pickle is inherently unsafe for untrusted data because it can embed object constructors and reduce functions that run code upon deserialization.
This maps to CWE-94: Improper Control of Generation of Code, as the application effectively allows untrusted serialized content to influence runtime behavior and execute attacker-specified operations when the cache is read.
Conceptually, the bug class is "unsafe, code-capable serialization of untrusted data" combined with implicit trust in the cache storage layer.
Potential impact
- Execution of arbitrary Python code under the victim application's privileges
- Reading, modifying, or deleting sensitive data accessible to the application
- Installation of backdoors or persistence mechanisms within the application environment
- Pivoting to other internal services or systems reachable from the compromised process
- Complete takeover of the host user account running the affected application
General mitigation guidance
Effective mitigation focuses on reducing trust in cache storage and avoiding code-capable serialization formats for untrusted data:
- Prefer non-executable serialization formats (e.g., JSON, msgpack, or custom safe encoders) instead of pickle for cache values.
- Treat cache directories as sensitive assets and restrict write permissions to the application account only; avoid placing caches on shared or world-writable locations.
- Introduce integrity protections (such as MACs or signatures) over cached content so that only data produced by trusted code is accepted.
- Limit what types of objects are cached; favor simple, structured data instead of complex or callable objects that encourage pickle usage.
- Run applications with least-privilege OS identities so that, even if cache-based code execution occurs, blast radius is constrained.
How teams detect issues like this
Organizations can look for this pattern by:
- Static analysis rules that flag use of pickle (and libraries that wrap it by default) in contexts where data can be influenced by external or shared sources.
- Code review checklists that question any use of executable serialization formats for caches, sessions, or IPC, especially when files are stored on shared volumes.
- Configuration reviews ensuring that DiskCache (and similar libraries) are explicitly configured with safe serializers and that cache directories are not world-writable.
- File integrity monitoring on cache directories to detect unexpected or untrusted modifications to cache files.
- Use of automated dependency and configuration scanning tools that highlight packages with unsafe-by-default serialization behaviors.

