CVE-2023-41334: Astropy Remote Code Execution Vulnerability
HIGHCVE-2023-41334 is a HIGH (CVSS 8.4) remote code execution vulnerability (CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')) affecting Astropy libraries in the PyPI ecosystem. The issue involves rce in tranformgraph().to_dot_graph function. Remediation is available by upgrading affected packages to version 5.3.3.
CVE-2023-41334 at a Glance
Security Impact
CVSS: 8.4
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).
How to Fix CVE-2023-41334
To remediate this vulnerability, upgrade all affected Astropy dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install astropy>=5.3.3
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show astropy
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2023-41334, inspect your installed packages using pip:
pip show astropy
Analyze the terminal output to locate any version of Astropy in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 5.3.3), your application is affected.
Note: The pip show astropy command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection'), where the product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component. In Astropy, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2023-41334 Affected Astropy Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
astropy
|
PyPI |
< 5.3.3
|
5.3.3
|
References
Frequently Asked Questions
What is CVE-2023-41334?
Which Astropy versions are affected?
What version fixes CVE-2023-41334?
Is astropy affected?
What is the CVSS score of CVE-2023-41334?
What CWE is associated with CVE-2023-41334?
How can I check PyPI dependencies for CVE-2023-41334?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-h2x6-5jx5-46hf",
"modified" : "2024-03-18T21:46:18Z",
"published" : "2024-03-18T20:26:33Z",
"aliases" : [ "CVE-2023-41334" ],
"summary" : "RCE in TranformGraph().to_dot_graph function",
"details" : "### Summary\nRCE due to improper input validation in TranformGraph().to_dot_graph function\n\n### Details\n\nDue to improper input validation a malicious user can provide a command or a script file as a value to `savelayout` argument, which will be placed as the first value in a list of arguments passed to `subprocess.Popen`. \nhttps://github.com/astropy/astropy/blob/9b97d98802ee4f5350a62b681c35d8687ee81d91/astropy/coordinates/transformations.py#L539\nAlthough an error will be raised, the command or script will be executed successfully.\n\n### PoC\n\n```shell\n$ cat /tmp/script\n#!/bin/bash\necho astrorce > /tmp/poc.txt\n```\n```shell\n$ python3\nPython 3.9.2 (default, Feb 28 2021, 17:03:44) \n[GCC 10.2.1 20210110] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> from astropy.coordinates.transformations import TransformGraph\n>>> tg = TransformGraph()\n>>> tg.to_dot_graph(savefn=\"/tmp/1.txt\", savelayout=\"/tmp/script\")\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/home/u32i/.local/lib/python3.9/site-packages/astropy/coordinates/transformations.py\", line 584, in to_dot_graph\n stdout, stderr = proc.communicate(dotgraph)\n File \"/usr/lib/python3.9/subprocess.py\", line 1134, in communicate\n stdout, stderr = self._communicate(input, endtime, timeout)\n File \"/usr/lib/python3.9/subprocess.py\", line 1961, in _communicate\n input_view = memoryview(self._input)\nTypeError: memoryview: a bytes-like object is required, not 'str'\n>>> \n```\n```shell\n$ cat /tmp/poc.txt\nastrorce\n```\n\n### Impact\ncode execution on the user's machine\n",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "astropy"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "5.3.3"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/astropy/astropy/security/advisories/GHSA-h2x6-5jx5-46hf"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-41334"
}, {
"type" : "WEB",
"url" : "https://github.com/astropy/astropy/commit/22057d37b1313f5f5a9b5783df0a091d978dccb5"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/astropy/astropy"
}, {
"type" : "WEB",
"url" : "https://github.com/astropy/astropy/blob/9b97d98802ee4f5350a62b681c35d8687ee81d91/astropy/coordinates/transformations.py#L539"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-74", "CWE-77" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2024-03-18T20:26:33Z",
"nvd_published_at" : "2024-03-18T19:15:05Z"
}
}