arbitrary code execution when loading a model via from_pickle (CWE-502)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- numpy, python, scikit-learn
- Ambito
- machine-learning, security
Direzione di ricerca
Start with tslearn/bases/bases.py, especially from_pickle() around line 302 and the to_pickle() method around line 288. Review how estimator models are serialized and which classes they need during loading; the report proposes a restricted unpickler but does not identify a complete safe allow-list. Done means untrusted pickle data cannot execute arbitrary code while legitimate saved models still load.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Loading an attacker-supplied model file with a tslearn estimator's from_pickle() runs arbitrary Python code as the user. The classmethod passes the file to pickle.load, which executes any __reduce__ gadget in the stream during deserialization, before the model is returned. from_pickle() is the documented counterpart to to_pickle() and is inherited by every tslearn estimator, reached with no option set, so opening a shared or downloaded model file is enough.
Details
The entry point is the base-class loader that every tslearn estimator inherits, in tslearn/bases/bases.py (main at d0708f25ad68):
302 def from_pickle(cls, path):
...
315 model = pickle.load(open(path, 'rb'))
from_pickle() opens path (a path the caller supplies) and calls pickle.load on it with no restricted unpickler and no allow-list. pickle.load runs a crafted file's __reduce__ at load time, so the whole file is attacker-controlled code. Models are meant to be saved and shared (to_pickle() writes this format at line 288), so a received model file is a normal input, not an unusual one.
Proof of concept
Tested with tslearn 0.10.0, Python 3.13 on Linux.
Build a file whose object runs a benign marker, then load it the documented way:
import pickle, os
class Evil:
def __reduce__(self):
return (os.system, ("id > /tmp/tslearn_poc",))
with open("model.pkl", "wb") as f:
pickle.dump(Evil(), f)
from tslearn.clustering import TimeSeriesKMeans
TimeSeriesKMeans.from_pickle("model.pkl")
/tmp/tslearn_poc then holds the output of id; the command runs before from_pickle() returns. The control is the same call on a legitimate model saved with to_pickle(): it loads to its estimator and runs nothing. The gadget is the only difference between the two runs.
Impact
Any user that loads a tslearn model received from someone else (a shared trained estimator, a downloaded artifact, a file attached to a report) runs that sender's code with their own privileges: file access, credential theft, lateral movement.
Suggested fix
In tslearn/bases/bases.py, load through a restricted Unpickler whose find_class allows only the tslearn, sklearn and numpy classes a model needs, and reject everything else; prefer the existing to_hdf5/to_json paths for untrusted exchange. Until then, document on from_pickle() that model files from untrusted sources must not be loaded.
Affected
- Package:
tslearn(PyPI) - Affected versions:
<= 0.10.0(through default-branch HEADd0708f25) - Patched versions: none
- Severity:
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H - Weaknesses: CWE-502
Credit
Dilanka Kaushal Hewage (r3vpwnx) [email protected]
- Lingua principale
- Python
- Stelle
- 3.2k
- Fork
- 418
- Merge medio
- 2g 14h
- PR unite (30g)
- 24
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tslearn-team/tslearn
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
tslearn-team/tslearn#854 ·
I maintainer di solito rispondono entro 1 giorno
-
Negative sakoe_chiba_radius is silently accepted: dtw/ctw/frechet return inf and lcss returns 0Forse già presa @MohamedO6 l’ha presa oggi. Aperta
tslearn-team/tslearn#857 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
tslearn-team/tslearn#855 ·
I maintainer di solito rispondono entro 1 giorno
-
PAA / SAX / 1d-SAX silently return NaN or garbage when n_segments is larger than the series lengthForse già presa @MohamedO6 l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 20/100
tslearn-team/tslearn#852 ·
I maintainer di solito rispondono entro 1 giorno
-
Time series scalers reject ragged lists despite variable-length supportForse già presa @sunlishuo25 l’ha presa 62 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
tslearn-team/tslearn#751 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di tslearn-team/tslearn
Issue simili
-
docs(contributing): the two things that silently block a PRForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaavailable documentation good first issue
Difficoltà 1/5 1-3 ore Idoneità per principianti 95/100
Nixitov/Riptide-Native#944 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
JTHCode/secretguard#24 ·
I maintainer di solito rispondono entro 1 giorno
-
area: middleware documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
omarelshamy25x/shamy-hijri#63 ·
I maintainer di solito rispondono entro 1 giorno