stingray: arbitrary code execution reading a pickle-format data product (read fmt=pickle) (CWE-502)

Open
#1,037 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

@yash-8923 is already working on this.

Since Nov 24, 2026.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
security

Research direction

Start in stingray/base.py at StingrayObject.read, where fmt == "pickle" calls pickle.load; trace how EventList, Lightcurve, Powerspectrum, and StingrayTimeseries inherit it. Read the existing read/write tests to see how pickle round-trips are covered, then reproduce with the PoC. Done when the gadget no longer executes, legitimate stingray pickle products still load, and a regression test covers both.

Written by the indexing model from the issue text.

Description

Summary

Loading a stingray data product saved in the pickle format runs arbitrary code as the user. StingrayObject.read(fmt="pickle") deserializes the file with a stock pickle.load. Local file, one read, full code execution.

Details

In stingray/base.py, StingrayObject.read dispatches on fmt and for pickle does:

elif fmt.lower() == "pickle":
    with open(filename, "rb") as fobj:
        return pickle.load(fobj)

a stock unpickler with no restriction. read is inherited by EventList, Lightcurve, Powerspectrum and StingrayTimeseries, and pickle is a documented value of fmt, paired with write(fmt="pickle"). A __reduce__ gadget in the file runs during the load. Present on the default branch HEAD.

Proof of concept
import pickle
class Exploit:
    def __reduce__(self):
        return (__import__('os').system, ('id > /tmp/stingray_poc',))
open("evil.pickle", "wb").write(pickle.dumps(Exploit()))

from stingray import EventList
EventList.read("evil.pickle", fmt="pickle")

id runs during the read. A benign pickled EventList loads without running anything. Confirmed on stingray 2.3.2, Python 3 on Linux.

Impact

stingray data products (event lists, light curves, power spectra) are saved and exchanged with write(fmt="pickle") / read(fmt="pickle"); the pickle format is documented. A user loading a shared .pickle product runs the sender's code. (The simulator's eval("models." + model_str) is a separate injection point if model_str is file-controlled.)

Suggested fix

Read the pickle with a restricted Unpickler whose find_class allow-lists only the stingray classes, or deprecate the pickle format in favor of the HDF5/FITS/ASCII paths. At minimum, document that pickle-format products must come from a trusted source.

Affected
  • Package: stingray
  • Affected versions: <= 2.3.2 (and main HEAD)
  • Severity: CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H (7.8)
  • Weaknesses: CWE-502
Credit

Dilanka Kaushal Hewage (r3vpwnx)

Dominant language
Python
Stars
229
Forks
196
Avg merge
4d 12h
Merged PRs (30d)
20

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from StingraySoftware/stingray

All issues in StingraySoftware/stingray

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.