A high-severity code-injection defect in HyperSpy lets a crafted scientific data file run arbitrary Python when a user opens it. The maintainers track it as GHSA-632c-gw75-99r3 with a CVSS 3.1 score of 7.8, and no CVE has been assigned.
It affects HyperSpy 2.0.0 through 2.5.0 and 1.2.0 through 1.7.6, and the fix ships in 2.6.0. HyperSpy stores mathematical expressions as plain strings inside its files. In affected builds, those strings reach sympy.sympify(), which parses text through Python eval() with real builtins.
The SymPy documentation warns that the function should never process unsanitized input. Any attacker-controlled attribute that feeds this call becomes a direct path to interpreter-level execution.
HyperSpy Code Injection Flaw
The maintainers classify the defect under CWE-94, Improper Control of Generation of Code, and also under CWE-95, which covers improper neutralization of directives in dynamically evaluated code.
The sinks sit in _components/expression.py, component.py and axes.py in HyperSpy 2.5.0. These are several triggers into one expression-evaluation weakness class. They are not separate claims about unsafe cloudpickle deserialization or class pollution.
The most dangerous route fires during an ordinary hs.load() call on a file with a crafted functional axis. It also fires with lazy=True, because lazy loading does not defer axis construction and is not a security boundary. Two more routes fire when a user restores a stored model with s.models.restore(name).
One is a poisoned Expression.expression attribute, and the other is a poisoned twin_function_expr parameter. The maintainers also fixed an inverse-twin sibling of the twin-expression route during an expanded internal audit.
That audit found further paths through rotation coordinates, nested signals and later fitting operations.
The proof of concept is deliberately benign. It saves a signal with the functional axis a / (x + 1) + b, then edits the HDF5 expression attribute with h5py.
The new value appends a term that multiplies zero by a pathlib write call, so the math result stays unchanged. On HyperSpy 2.5.0, hs.load() returns a normal-looking signal and the marker file appears in /tmp. On the remediated branch, parsing raises ValueError before the marker is created.
The attack vector is local, complexity is low, no privileges are required, and user interaction is required. This is not a zero-click network-service compromise. An attacker must convince a researcher to open a crafted file, restore a stored model, or fit a restored model. Those are routine data-exchange actions in electron microscopy and spectroscopy labs.
Successful exploitation runs Python with the victim’s privileges and rates High for confidentiality, integrity and availability. On shared analysis workstations, that exposes SSH keys, cloud tokens, notebooks and unpublished datasets. Researchers should treat .hspy and .zspy files from outside collaborators with the same caution as executable scripts.
Nils Jordan (nOrdan05) privately reported the stored-expression and twin-expression execution during model restoration on 2026-11-10. Dilanka Kaushal Hewage (r3vpwnx) publicly reported the functional-axis hs.load() route in hyperspy/hyperspy#3699 on 2026-11-13. Maintainer Francisco de la Peña published the advisory on GitHub.
Cloudpickle deserialization, class pollution and learning-results NPZ deserialization are tracked separately. Those are GHSA-j975-x368-3hrr, GHSA-5p52-6h39-38rr and GHSA-9wjw-mpmw-qph4. Defenders should review all four together, because a single hardened path does not close the others.
Dynamic evaluation of file-derived strings keeps producing remote and local code-execution defects in developer tooling. Semgrep’s guidance notes that pickle-style deserialization cannot be made safe against arbitrary input. The same logic applies to eval()-backed parsers such as sympify().
Recent coverage on a GitHub git-push command injection chain shows how one unsanitized value can escalate to backend execution. Attackers are also using Python heavily in intrusions, as seen in the AI-assisted CL-UNK-1211 campaign delivering SysGoRAT. Teams can follow related incidents in the Cyber Security News archive.
Mitigation
HyperSpy 2.6.0 replaces file-derived sympify() evaluation with a restricted, bounded expression parser. Functional-axis, component and twin-expression handling all pass through it.
The parser is not a general CPU or memory sandbox, so oversized expressions can still consume resources. The release targets Python 3.11 or later and RosettaSciIO 0.16.0 or later.
Upgrading HyperSpy alone does not fix RosettaSciIO-owned readers, so both packages must be updated together. The 1.x series is end-of-life and receives no backport. Until the upgrade is done, administrators should avoid opening or restoring models from untrusted .hspy or .zspy files.
They should also avoid building models from untrusted dictionaries. Where possible, run analysis in containers with no credential mounts or outbound network access.
FAQ
Which HyperSpy versions are affected? HyperSpy 2.0.0 through 2.5.0 and 1.2.0 through 1.7.6 are affected, and 2.6.0 is the fixed release.
Is this a remote zero-click attack? No, it needs user interaction such as loading a crafted file, restoring a stored model, or fitting a restored model.
Does lazy loading prevent exploitation? No, lazy=True does not defer axis construction, so the payload still executes during hs.load().
Does upgrading HyperSpy alone fully fix the issue? No, you must also install the fixed RosettaSciIO, version 0.16.0 or later.