Skip to main content

pickle-sentry

Scan code and dataset files for unsafe pickle deserialization — including the Hugging Face datasets pandas builder RCE, CVE-2026-57845 (CVSS 8.8).

Pickle is code, not data. Any file, checkpoint, or dataset that passes through a pickle loader executes whatever its author put in it. pickle-sentry finds those paths in your code, and inspects pickle files by disassembly only — it never executes the files it inspects (its test suite proves this with a canary payload).

Why now

CVE-2026-57845 (published 23 Oct 2026): Hugging Face datasets through 5.1.0 — the latest release — routes load_dataset("pandas", data_files=...) to pandas.read_pickle(). A crafted pickle runs arbitrary Python with the victim's privileges the moment the dataset loads. The upstream fix (huggingface/datasets#8879) disables the pandas builder, but no patched release exists yet. Until one ships, the mitigation is: find every place you load pickle-backed data, and migrate to Parquet / CSV / JSON / Arrow.

Install

pip install -e .

Zero dependencies. Python 3.9+.

Use

pickle-sentry scan-path/                     # text report, exit 1 on high+
pickle-sentry . --format json --output report.json
pickle-sentry . --format sarif --output report.sarif   # for GitHub code scanning
pickle-sentry . --fail-on critical           # CI: only fail on critical
pickle-sentry . --exclude /tests/            # production surface only

Scan a Hugging Face Hub repo (new in 0.2.0)

pickle-sentry hub stanfordnlp/imdb                          # a dataset
pickle-sentry hub hf-internal-testing/tiny-random-bert --repo-type model
pickle-sentry hub user/repo --max-size-mb 16 --format json

Lists the repo's files via the Hub API, downloads pickle-family files (.pkl, .pickle, .joblib, .pt, .pth, and classic pytorch_model.bin) and inspects them by disassembly — including the pickle stream inside torch zip archives — and AST-scans any Python files in the repo. Files over the size cap are flagged, not downloaded. Set HF_TOKEN for private repos. Nothing downloaded is ever executed.

What it catches

In Python code (AST scan — parses, never imports your code):

Rule Severity What
HF-DATASETS-PANDAS-BUILDER critical load_dataset("pandas", ...) — CVE-2026-57845
UNSAFE-DESERIALIZATION high pickle.load/loads, dill, cloudpickle, marshal, shelve, joblib.load
PANDAS-READ-PICKLE high pandas.read_pickle(...)
TORCH-LOAD-WEIGHTS-ONLY-FALSE high torch.load(..., weights_only=False)
TORCH-LOAD-NO-WEIGHTS-ONLY medium torch.load(...) with no explicit weights_only=True
YAML-UNSAFE-LOAD medium yaml.load(...) without a SafeLoader
NUMPY-ALLOW-PICKLE high numpy.load(..., allow_pickle=True)

In data files (disassembly via pickletools, never unpickled):

Rule Severity What
PICKLE-DANGEROUS-REDUCE critical Pickle calls os.system, subprocess.*, eval, exec, etc. via REDUCE
PICKLE-REDUCE-CALLABLE high Pickle invokes a non-standard callable via REDUCE (the CVE PoC payload's shape)
PICKLE-DANGEROUS-GLOBAL / PICKLE-SUSPICIOUS-MODULE high/medium Dangerous globals referenced without a reduce
PICKLE-FILE-PRESENT medium Any other .pkl / .pickle / .joblib file, and pickle streams inside torch .pt/.pth zip archives

Real-life use case

docs/USE-CASE.md walks through a real one end to end: scanning the actual published CVE-2026-57845 PoC repository before touching it. pickle-sentry flags the vulnerable loader (run_poc.py:139, critical) and disassembles the live payload (attacker-controlled.pkl, high) — and the PoC's own marker.txt proves the payload never executed during the scan.

Live examples

Scanned two real codebases on 9 Nov 2026 — full results, methodology, and honest limits in docs/LIVE-EXAMPLES.md:

  • huggingface/datasets: 258 files, 24 findings — and exactly one in production source: the CVE sink itself, pd.read_pickle(f) at packaged_modules/pandas/pandas.py:56.
  • scikit-learn: 1,037 files, 73 findings — 16 outside tests, concentrated in sklearn/datasets/ loaders unpickling cached copies of remotely fetched datasets.

Also included: a composite GitHub Action (action.yml, use it as uses: Sun-Wukhan/pickle-sentry@main) and a pre-commit hook (.pre-commit-hooks.yaml). Use --exclude /tests/ to cut test-fixture noise.

Demo

pickle-sentry examples/vulnerable   # flags the CVE pattern + every sink, exit 1
pickle-sentry examples/safe         # clean, exit 0
pickle-sentry examples/hf-datasets-pandas.py
# ^ the actual upstream datasets pandas builder (verbatim from
#   huggingface/datasets main): flags pd.read_pickle(f) at line 56 —
#   the exact sink behind CVE-2026-57845.

Migrate off pickle

  • Datasets: load_dataset("parquet" | "csv" | "json" | "arrow", ...)
  • Your own DataFrame: Dataset.from_pandas(df) instead of a pickle file
  • DataFrames on disk: df.to_parquet(...) / pd.read_parquet(...)
  • Torch: torch.load(path, weights_only=True)

Tests

pip install pytest
pytest

The inspector tests build a real malicious pickle (__reduce__ → os.system) and assert two things: it is flagged critical, and the payload's canary file never appears — i.e. inspection did not execute it.

Licence

MIT

Metadata

Release files for pickle-sentry 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pickle-sentry 0.2.0
File Size Uploaded Provenance Actions
pickle_sentry-0.2.0.tar.gz 17.5 kB With provenance Details for pickle_sentry-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pickle-sentry 0.2.0
File Interpreter ABI Platform Actions
pickle_sentry-0.2.0-py3-none-any.whl Python 3 none any Details for pickle_sentry-0.2.0-py3-none-any.whl

Total release size: 33.0 kB

Release files / pickle_sentry-0.2.0.tar.gz

Download URL pickle_sentry-0.2.0.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fee28214f51c15530341815c549903d4261398a4a999e8ea1e2ac5f3d19cad45
BLAKE2b-256 checksum
How to use checksums
6e28c7285d68beb52434765fc10809018477706a6ebf1f86a04ad95809a69f4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / pickle_sentry-0.2.0-py3-none-any.whl

Download URL pickle_sentry-0.2.0-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7886d25e36991e0bd9d44d32adb8326f8ba4034bcbcec14cf79937fde43ad84
BLAKE2b-256 checksum
How to use checksums
6d0abcb12fe65a807e9337e3bb600a2bd58c272bf1dd0d4e5372d9c8ad1d06a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for pickle-sentry 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pickle_sentry-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page