Summary
diffpy.structure can execute Python code when crafted CIF symmetry-operation values are passed to eval() in get_symop(). If a victim parses a malicious CIF file, embedded expressions may run with the privileges of the parsing process.
Affected context
The issue affects diffpy.structure versions before 3.5.1 when CIF files are parsed and symmetry operations are read from the _space_group_symop_operation_xyz or _symmetry_equiv_pos_as_xyz loop. Risk depends on whether an attacker can supply a CIF file that a victim or automated workflow subsequently parses.
Exploit preconditions
- Attack surface: Local CIF file parsing
- Required access: Ability to provide or influence a CIF file that the victim parses
- Trigger point: Processing symmetry-operation values in
get_symop() - Why exploitation is possible: Crafted values reach Python's
eval()and may be interpreted as executable expressions
Why this happens
The parser evaluates symmetry-operation input as Python code rather than treating it strictly as data. This is an eval injection weakness mapped to CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code. Untrusted CIF content can therefore cross from data parsing into code execution.
Potential impact
- An attacker may execute Python code with the parsing process's privileges.
- Local files or accessible data could be read, changed, or deleted.
- The affected application or workflow could be disrupted.
- Credentials or other resources available to the process could be exposed.
General mitigation guidance
Defensive patterns focus on preventing untrusted input from being interpreted as code.
- Replace dynamic evaluation with a dedicated parser or strict, non-executable grammar for symmetry operations.
- Validate parsed values against an explicit schema and reject unexpected syntax before use.
- Treat CIF files from external or user-controlled sources as untrusted.
- Parse files in an isolated, least-privilege environment with limited filesystem and network access.
- Avoid passing raw configuration or file content to general-purpose evaluation functions.
How teams detect issues like this
- Use static analysis to identify
eval()and similar dynamic execution functions that receive file-derived or otherwise untrusted values. - Review parsing paths to confirm CIF fields cannot reach code-evaluation APIs.
- Add tests and policy checks that reject executable parsing patterns and unexpected symmetry-operation syntax.
- Consider automated code review tools to flag data-to-evaluation flows.

