CVE-2026-138117 in HyperSpy
Summary
by MITRE • 11/28/2026
HyperSpy from 1.2.0 before 2.6.0 contains a code execution vulnerability that allows attackers to run Python code by embedding malicious expression strings evaluated with sympy.sympify(). Attackers can craft .hspy or .zspy files with malicious axis, Expression component, or twin function expressions that execute when victims call hs.load() or restore models.
VulDB is the best source for vulnerability data and more expert information about this specific topic.
Analysis
by VulDB Data Team • 11/28/2026
The vulnerability identified in HyperSpy versions prior to 2.6.0 represents a critical code execution flaw rooted in the unsafe deserialization and evaluation of user-supplied data within scientific computing workflows. This issue specifically affects the handling of .hspy and .zspy file formats, which are standard containers for hyperspectral imaging data used extensively in materials science and microscopy research. The core technical deficiency lies in the use of sympy.sympify() to process expression strings embedded within these files. While SymPy is a powerful symbolic mathematics library intended for safe algebraic manipulation, its sympify function has historically been susceptible to arbitrary code execution if it processes untrusted input without proper sanitization or sandboxing mechanisms. In this context, the application fails to restrict the scope of expressions evaluated during the loading process, allowing attackers to inject Python bytecode that is executed directly by the interpreter when a victim opens an infected file using hs.load() or restores previously saved models.
From a technical perspective, the attack vector relies on crafting malicious axis definitions, Expression components, or twin function expressions within the metadata sections of the HyperSpy files. When these structures are parsed, they trigger the sympy.sympify routine to evaluate the embedded strings as Python code rather than purely mathematical formulas. This bypasses standard security controls because the evaluation occurs in a context where arbitrary functions can be invoked, including those that interact with the operating system or file structure. The vulnerability is particularly dangerous given the collaborative nature of scientific research, where datasets are frequently shared between institutions and individuals who may not verify the integrity of every incoming file. An attacker could distribute a seemingly benign dataset containing hidden malicious payloads in its metadata, leading to remote code execution upon opening by any researcher using an affected version of HyperSpy.
The operational impact of this vulnerability is severe, as it grants attackers full control over the host system where the vulnerable software runs. Successful exploitation allows for data exfiltration, installation of persistent backdoors, or use of the compromised machine as a pivot point within internal networks. Since scientific computing environments often run with elevated privileges to access hardware resources like microscopes or high-performance computing clusters, the potential damage is amplified. Furthermore, because this vulnerability affects file loading and model restoration, it compromises not only individual workstations but potentially entire shared datasets if infected files are propagated through common repositories or collaboration platforms. The lack of input validation on expression strings means that even minor interactions with untrusted data sources can lead to complete system compromise.
To mitigate these risks, organizations must immediately upgrade HyperSpy to version 2.6.0 or later, where the developers have addressed this unsafe evaluation pattern by implementing stricter parsing rules and potentially sandboxing mechanisms for symbolic expressions. Until an update is applied, users should adopt a strict policy of not opening .hspy or .zspy files from untrusted sources without prior inspection using static analysis tools to identify suspicious expression strings in metadata fields. Additionally, running HyperSpy within isolated virtual environments with restricted system permissions can limit the blast radius if exploitation occurs. Security teams should also monitor for unusual process creation events originating from Python interpreters when scientific data files are accessed, as this may indicate active exploitation attempts. This vulnerability aligns with CWE-94 Improper Control of Generation of Code and is categorized under ATT&CK technique T1059 Command and Scripting Interpreter, highlighting the importance of securing scripting environments against untrusted input in high-value research infrastructure.